Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
import org.apache.ambari.server.orm.entities.BlueprintConfigEntity;
import org.apache.ambari.server.orm.entities.BlueprintConfiguration;
import org.apache.ambari.server.orm.entities.BlueprintEntity;
import org.apache.ambari.server.orm.entities.BlueprintMpackInstanceEntity;
import org.apache.ambari.server.orm.entities.BlueprintSettingEntity;
import org.apache.ambari.server.orm.entities.HostGroupComponentEntity;
import org.apache.ambari.server.orm.entities.HostGroupEntity;
import org.apache.ambari.server.orm.entities.StackEntity;
import org.apache.ambari.server.stack.NoSuchStackException;
import org.apache.ambari.server.state.SecurityType;
import org.apache.ambari.server.state.StackInfo;
Expand Down Expand Up @@ -309,11 +309,8 @@ public Void invoke() throws AmbariException {
* @return a new resource instance for the given blueprint entity
*/
protected Resource toResource(BlueprintEntity entity, Set<String> requestedIds) throws NoSuchResourceException {
StackEntity stackEntity = entity.getStack();
Resource resource = new ResourceImpl(Resource.Type.Blueprint);
setResourceProperty(resource, BLUEPRINT_NAME_PROPERTY_ID, entity.getBlueprintName(), requestedIds);
setResourceProperty(resource, STACK_NAME_PROPERTY_ID, stackEntity.getStackName(), requestedIds);
setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, stackEntity.getStackVersion(), requestedIds);

List<Map<String, Object>> listGroupProps = new ArrayList<>();
Collection<HostGroupEntity> hostGroups = entity.getHostGroups();
Expand Down Expand Up @@ -377,11 +374,14 @@ List<Map<String, Map<String, Object>>> populateConfigurationList(
Map<String, String> properties = jsonSerializer.<Map<String, String>>fromJson(
config.getConfigData(), Map.class);

StackEntity stack = ((BlueprintConfigEntity)config).getBlueprintEntity().getStack();

// TODO: use multiple mpacks
BlueprintMpackInstanceEntity mpack =
((BlueprintConfigEntity)config).getBlueprintEntity().getMpackReferences().iterator().next();
StackInfo metaInfoStack;

try {
metaInfoStack = ambariMetaInfo.getStack(stack.getStackName(), stack.getStackVersion());
metaInfoStack = ambariMetaInfo.getStack(mpack.getMpackName(), mpack.getMpackVersion());
} catch (AmbariException e) {
throw new NoSuchResourceException(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@

package org.apache.ambari.server.orm.dao;


import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import org.apache.ambari.server.orm.RequiresSession;
import org.apache.ambari.server.orm.entities.BlueprintEntity;
import org.apache.ambari.server.orm.entities.StackEntity;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.persist.Transactional;


/**
* Blueprint Data Access Object.
*/
Expand Down Expand Up @@ -82,7 +79,6 @@ public List<BlueprintEntity> findAll() {
*/
@Transactional
public void refresh(BlueprintEntity blueprintEntity) {
ensureStackIdSet(blueprintEntity);
entityManagerProvider.get().refresh(blueprintEntity);
}

Expand All @@ -93,7 +89,6 @@ public void refresh(BlueprintEntity blueprintEntity) {
*/
@Transactional
public void create(BlueprintEntity blueprintEntity) {
ensureStackIdSet(blueprintEntity);
entityManagerProvider.get().persist(blueprintEntity);
}

Expand All @@ -105,7 +100,6 @@ public void create(BlueprintEntity blueprintEntity) {
*/
@Transactional
public BlueprintEntity merge(BlueprintEntity blueprintEntity) {
ensureStackIdSet(blueprintEntity);
return entityManagerProvider.get().merge(blueprintEntity);
}

Expand All @@ -116,7 +110,6 @@ public BlueprintEntity merge(BlueprintEntity blueprintEntity) {
*/
@Transactional
public void remove(BlueprintEntity blueprintEntity) {
ensureStackIdSet(blueprintEntity);
entityManagerProvider.get().remove(merge(blueprintEntity));
}

Expand All @@ -128,11 +121,4 @@ public void remove(BlueprintEntity blueprintEntity) {
public void removeByName(String blueprint_name) {
entityManagerProvider.get().remove(findByName(blueprint_name));
}

private void ensureStackIdSet(BlueprintEntity entity) {
StackEntity stack = entity.getStack();
if (stack != null && stack.getStackId() == null) {
entity.setStack(stackDAO.find(stack.getStackName(), stack.getStackVersion()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.ambari.server.orm.entities;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Basic;
Expand All @@ -27,10 +28,8 @@
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.apache.ambari.server.state.SecurityType;
Expand Down Expand Up @@ -58,22 +57,18 @@ public class BlueprintEntity {
@Basic
@Column(name = "security_descriptor_reference", nullable = true, insertable = true, updatable = true)
private String securityDescriptorReference;

/**
* Unidirectional one-to-one association to {@link StackEntity}
*/
@OneToOne
@JoinColumn(name = "stack_id", unique = false, nullable = false, insertable = true, updatable = false)
private StackEntity stack;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint")
private Collection<HostGroupEntity> hostGroups = new ArrayList<>();

@OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint")
private Collection<HostGroupEntity> hostGroups;
private Collection<BlueprintConfigEntity> configurations = new ArrayList<>();

@OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint")
private Collection<BlueprintConfigEntity> configurations;
private Collection<BlueprintSettingEntity> settings = new ArrayList<>();

@OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint")
private Collection<BlueprintSettingEntity> settings;
private Collection<BlueprintMpackInstanceEntity> mpackReferences = new ArrayList<>();


/**
Expand All @@ -94,25 +89,6 @@ public void setBlueprintName(String blueprintName) {
this.blueprintName = blueprintName;
}

/**
* Gets the blueprint's stack.
*
* @return the stack.
*/
public StackEntity getStack() {
return stack;
}

/**
* Sets the blueprint's stack.
*
* @param stack
* the stack to set for the blueprint (not {@code null}).
*/
public void setStack(StackEntity stack) {
this.stack = stack;
}

/**
* Get the collection of associated host groups.
*
Expand Down Expand Up @@ -182,4 +158,12 @@ public String getSecurityDescriptorReference() {
public void setSecurityDescriptorReference(String securityDescriptorReference) {
this.securityDescriptorReference = securityDescriptorReference;
}

public Collection<BlueprintMpackInstanceEntity> getMpackReferences() {
return mpackReferences;
}

public void setMpackReferences(Collection<BlueprintMpackInstanceEntity> mpackReferences) {
this.mpackReferences = mpackReferences;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ambari.server.orm.entities;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
* Entity to represent an mpack level configuration in the blueprint.
*/
@Entity
@Table(name = "blueprint_mpack_configuration")
@IdClass(BlueprintMpackConfigEntityPk.class)
public class BlueprintMpackConfigEntity implements BlueprintConfiguration {

@Id
@Column(name = "mpack_ref_id", nullable = false, insertable = false, updatable = false)
private Long mpackRefId;

@Id
@Column(name = "type_name", nullable = false, insertable = true, updatable = false, length = 100)
private String type;

@Column(name = "config_data")
@Basic(fetch = FetchType.LAZY)
@Lob
private String configData;

@Column(name = "config_attributes")
@Basic(fetch = FetchType.LAZY)
@Lob
private String configAttributes;

@ManyToOne
@JoinColumn(name = "mpack_ref_id", referencedColumnName = "id", nullable = false)
private BlueprintMpackInstanceEntity mpackReference;

/**
* @return the id of the mpack referency entity this configuration belongs to
*/
public Long getMpackRefId() {
return mpackRefId;
}

/**
* @param mpackRefId the id of the mpack referency entity this configuration belongs to
*/
public void setMpackRefId(Long mpackRefId) {
this.mpackRefId = mpackRefId;
}

/**
* @return the configuration type
*/
@Override
public String getType() {
return type;
}

/**
* @param typeName the type of the configuration
*/
@Override
public void setType(String typeName) {
this.type = typeName;
}

/**
* @return the configuration data encoded in json
*/
public String getConfigData() {
return configData;
}

/**
* @param blueprintName the name of the blueprint
*/
@Override
public void setBlueprintName(String blueprintName) {
throw new UnsupportedOperationException();
}

/**
* @return the name of the blueprint
*/
@Override
public String getBlueprintName() {
return getMpackReference().getBlueprint().getBlueprintName();
}

/**
* @param configData the configuration data encoded in json
*/
public void setConfigData(String configData) {
this.configData = configData;
}

/**
* @return the configuration attributes encoded in json
*/
public String getConfigAttributes() {
return configAttributes;
}

/**
* @param configAttributes the configuration attributes encoded in json
*/
public void setConfigAttributes(String configAttributes) {
this.configAttributes = configAttributes;
}

/**
* @return the mpack referency entity this configuration belongs to
*/
public BlueprintMpackInstanceEntity getMpackReference() {
return mpackReference;
}

/**
* @param mpackReference the mpack referency entity this configuration belongs to
*/
public void setMpackReference(BlueprintMpackInstanceEntity mpackReference) {
this.mpackReference = mpackReference;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ambari.server.orm.entities;

import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Id;

/**
* Composite primary key for {@link BlueprintMpackConfigEntity}
*/
public class BlueprintMpackConfigEntityPk {
@Id
@Column(name = "mpack_ref_id", nullable = false, insertable = true, updatable = false)
private Long mpackRefId;

@Id
@Column(name = "type_name", nullable = false, insertable = true, updatable = false, length = 100)
private String type;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlueprintMpackConfigEntityPk that = (BlueprintMpackConfigEntityPk) o;
return Objects.equals(mpackRefId, that.mpackRefId) &&
Objects.equals(type, that.type);
}

@Override
public int hashCode() {
return Objects.hash(mpackRefId, type);
}
}
Loading