Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.ambari.server.orm.dao.HostDAO;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.dao.HostVersionDAO;
import org.apache.ambari.server.orm.dao.MpackDAO;
import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
import org.apache.ambari.server.orm.dao.RequestDAO;
import org.apache.ambari.server.orm.dao.ResourceTypeDAO;
Expand All @@ -65,6 +66,7 @@
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
import org.apache.ambari.server.orm.entities.HostStateEntity;
import org.apache.ambari.server.orm.entities.HostVersionEntity;
import org.apache.ambari.server.orm.entities.MpackEntity;
import org.apache.ambari.server.orm.entities.PrincipalEntity;
import org.apache.ambari.server.orm.entities.PrincipalTypeEntity;
import org.apache.ambari.server.orm.entities.RepoDefinitionEntity;
Expand Down Expand Up @@ -144,6 +146,9 @@ public class OrmTestHelper {
@Inject
private StackDAO stackDAO;

@Inject
MpackDAO mpackDAO;

private static final StackId HDP_206 = new StackId("HDP", "2.0.6");
public static final StackId STACK_ID = new StackId("HDP", "2.2.0");
public static final String CLUSTER_NAME = "test_cluster1";
Expand Down Expand Up @@ -326,14 +331,33 @@ public void createStageCommands() {
hostDAO.merge(host2);
}

@Transactional
public MpackEntity createMpack(StackId stackId) throws AmbariException {
List<MpackEntity> mpackEntities =
mpackDAO.findByNameVersion(stackId.getStackName(), stackId.getStackVersion());
MpackEntity mpackEntity = !mpackEntities.isEmpty() ? mpackEntities.get(0) : null;
if (mpackEntities.isEmpty()) {
mpackEntity = new MpackEntity();
mpackEntity.setMpackName(stackId.getStackName());
mpackEntity.setMpackVersion(stackId.getStackVersion());
mpackEntity.setMpackUri("http://mpacks.org/" + stackId.toString() + ".json");
mpackDAO.create(mpackEntity);
}
return mpackEntity;
}

@Transactional
public StackEntity createStack(StackId stackId) throws AmbariException {
StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());

if (null == stackEntity) {
stackEntity = new StackEntity();
stackEntity.setStackName(stackId.getStackName());
stackEntity.setStackVersion(stackId.getStackVersion());
List<MpackEntity> mpackEntities =
mpackDAO.findByNameVersion(stackId.getStackName(), stackId.getStackVersion());
if (!mpackEntities.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should call createMpack(stackId) instead of lookup, to ensure that all callers of this method are safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory and also according to the DB schema, stacks can exist without mpacks (legacy 2.x stacks) so I'd like to leave the flexibility to create such setups.

stackEntity.setMpackId(mpackEntities.get(0).getId());
}
stackDAO.create(stackEntity);
}

Expand Down Expand Up @@ -669,6 +693,7 @@ public RepositoryVersionEntity getOrCreateRepositoryVersion(StackId stackId,
String version) {
StackEntity stackEntity = null;
try {
createMpack(stackId); // creating mpack before stack makes sure stack will be linked to mpack
stackEntity = createStack(stackId);
} catch (Exception e) {
LOG.error("Expected successful repository", e);
Expand All @@ -695,9 +720,9 @@ public RepositoryVersionEntity getOrCreateRepositoryVersion(StackId stackId,
repoOsEntity.setAmbariManaged(true);
repoOsEntity.addRepoDefinition(repoDefinitionEntity1);
repoOsEntity.addRepoDefinition(repoDefinitionEntity2);
repoOsEntity.setMpackEntity(createMpack(stackId));
operatingSystems.add(repoOsEntity);


repositoryVersion = repositoryVersionDAO.create(stackEntity, version,
String.valueOf(System.currentTimeMillis()) + uniqueCounter.incrementAndGet(), operatingSystems);

Expand Down