Search in sources :

Example 1 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateService method deleteByName.

public ClusterTemplate deleteByName(String name, Long workspaceId) {
    ClusterTemplate clusterTemplate = getByNameForWorkspaceId(name, workspaceId);
    clusterTemplate = delete(clusterTemplate);
    ownerAssignmentService.notifyResourceDeleted(clusterTemplate.getResourceCrn(), MDCUtils.getRequestId());
    stackTemplateService.delete(clusterTemplate.getStackTemplate());
    return clusterTemplate;
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate)

Example 2 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateService method deleteByCrn.

public ClusterTemplate deleteByCrn(String crn, Long workspaceId, boolean internalTenant) {
    ClusterTemplate clusterTemplate = getByCrn(crn, workspaceId, internalTenant);
    clusterTemplate = delete(clusterTemplate);
    stackTemplateService.delete(clusterTemplate.getStackTemplate());
    return clusterTemplate;
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate)

Example 3 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateV4Controller method post.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_CLUSTER_DEFINITION)
public ClusterTemplateV4Response post(Long workspaceId, @Valid ClusterTemplateV4Request request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    String creator = ThreadBasedUserCrnProvider.getUserCrn();
    ClusterTemplate clusterTemplate = clusterTemplateService.createForLoggedInUser(clusterTemplateV4RequestToClusterTemplateConverter.convert(request), threadLocalService.getRequestedWorkspaceId(), accountId, creator);
    return getByName(threadLocalService.getRequestedWorkspaceId(), clusterTemplate.getName());
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 4 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateV4Controller method deleteByCrn.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DELETE_CLUSTER_DEFINITION)
public ClusterTemplateV4Response deleteByCrn(Long workspaceId, @TenantAwareParam @ResourceCrn String crn) {
    boolean internalTenant = isInternalTenant();
    ClusterTemplate clusterTemplate = clusterTemplateService.deleteByCrn(crn, threadLocalService.getRequestedWorkspaceId(), internalTenant);
    return clusterTemplateToClusterTemplateV4ResponseConverter.convert(clusterTemplate);
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 5 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate in project cloudbreak by hortonworks.

the class BlueprintLoaderServiceTest method testForTheSpecifiedUserWhenNewDefaultsExistAndNONeedsToRetireOldBlueprintsThenRepositoryShouldUpdateAddTwoNewAndReturnWithFive.

@Test
public void testForTheSpecifiedUserWhenNewDefaultsExistAndNONeedsToRetireOldBlueprintsThenRepositoryShouldUpdateAddTwoNewAndReturnWithFive() {
    Set<ClusterTemplate> notEmptyClusterTemplateList = Sets.newHashSet(new ClusterTemplate());
    // We have a0, a1, a2 in the DB
    Set<Blueprint> blueprints = generateBlueprintData(3, BlueprintUpgradeOption.ENABLED);
    // We have a2, a3, a4 as defaults
    Map<String, BlueprintFile> defaultBlueprints = generateCacheData(3, 2, BlueprintUpgradeOption.ENABLED);
    setupMock(defaultBlueprints);
    when(clusterTemplateService.getTemplatesByBlueprint(any(Blueprint.class))).thenReturn(notEmptyClusterTemplateList);
    Collection<Blueprint> resultSet = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.loadBlueprintsForTheWorkspace(blueprints, workspace, this::mockSave));
    ArgumentCaptor<Iterable<Blueprint>> argument = ArgumentCaptor.forClass(Iterable.class);
    verify(blueprintService).pureSaveAll(argument.capture());
    verify(blueprintService, times(1)).pureSaveAll(any(Iterable.class));
    Assert.assertEquals(0, Iterators.size(argument.getValue().iterator()));
    Assert.assertEquals(5L, resultSet.size());
    Assert.assertTrue(CollectionUtils.isEqualCollection(Sets.newHashSet("multi-node-hdfs-yarn0", "multi-node-hdfs-yarn1", "multi-node-hdfs-yarn2"), collectBpNames(blueprints)));
    Assert.assertTrue(CollectionUtils.isEqualCollection(Sets.newHashSet("multi-node-hdfs-yarn2", "multi-node-hdfs-yarn3", "multi-node-hdfs-yarn4"), defaultBlueprints.keySet()));
    Assert.assertTrue(CollectionUtils.isEqualCollection(Sets.newHashSet("multi-node-hdfs-yarn0", "multi-node-hdfs-yarn1", "multi-node-hdfs-yarn2", "multi-node-hdfs-yarn3", "multi-node-hdfs-yarn4"), collectBpNames(resultSet)));
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) Test(org.junit.Test)

Aggregations

ClusterTemplate (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate)37 Test (org.junit.jupiter.api.Test)13 DefaultClusterTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.requests.DefaultClusterTemplateV4Request)8 Test (org.junit.Test)8 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)7 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)6 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)6 ClusterTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.requests.ClusterTemplateV4Request)4 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)4 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)4 FeatureState (com.sequenceiq.cloudbreak.api.endpoint.v4.common.FeatureState)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)3 User (com.sequenceiq.cloudbreak.workspace.model.User)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3