Search in sources :

Example 1 with InstanceGroupRequest

use of com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest in project cloudbreak by hortonworks.

the class StackToStackResponseConverterTest method testConvertWithoutNetwork.

@Test
public void testConvertWithoutNetwork() {
    // GIVEN
    getSource().setNetwork(null);
    given(conversionService.convert(any(Object.class), any(Class.class))).willReturn(new ImageJson()).willReturn(new StackAuthenticationResponse()).willReturn(new CredentialResponse()).willReturn(new ClusterResponse()).willReturn(new FailurePolicyResponse()).willReturn(new OrchestratorResponse()).willReturn(new CloudbreakDetailsJson());
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<InstanceGroupRequest>());
    // WHEN
    StackResponse result = underTest.convert(getSource());
    // THEN
    assertAllFieldsNotNull(result, Arrays.asList("networkId", "platformVariant", "ambariVersion", "hdpVersion", "network", "flexSubscription"));
}
Also used : InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) CloudbreakDetailsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakDetailsJson) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) CredentialResponse(com.sequenceiq.cloudbreak.api.model.CredentialResponse) OrchestratorResponse(com.sequenceiq.cloudbreak.api.model.OrchestratorResponse) FailurePolicyResponse(com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) ImageJson(com.sequenceiq.cloudbreak.api.model.ImageJson) StackAuthenticationResponse(com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Test(org.junit.Test)

Example 2 with InstanceGroupRequest

use of com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest in project cloudbreak by hortonworks.

the class StackToStackResponseConverterTest method testConvertWithoutCredential.

@Test
public void testConvertWithoutCredential() {
    // GIVEN
    given(conversionService.convert(any(Object.class), any(Class.class))).willReturn(new ImageJson()).willReturn(new StackAuthenticationResponse()).willReturn(new CredentialResponse()).willReturn(new ClusterResponse()).willReturn(new FailurePolicyResponse()).willReturn(new NetworkResponse()).willReturn(new OrchestratorResponse()).willReturn(new CloudbreakDetailsJson());
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<InstanceGroupRequest>());
    // WHEN
    StackResponse result = underTest.convert(getSource());
    // THEN
    assertAllFieldsNotNull(result, Arrays.asList("credentialId", "cloudPlatform", "platformVariant", "ambariVersion", "hdpVersion", "stackTemplate", "cloudbreakDetails", "flexSubscription"));
}
Also used : InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) CloudbreakDetailsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakDetailsJson) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) CredentialResponse(com.sequenceiq.cloudbreak.api.model.CredentialResponse) OrchestratorResponse(com.sequenceiq.cloudbreak.api.model.OrchestratorResponse) FailurePolicyResponse(com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) ImageJson(com.sequenceiq.cloudbreak.api.model.ImageJson) NetworkResponse(com.sequenceiq.cloudbreak.api.model.NetworkResponse) StackAuthenticationResponse(com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Test(org.junit.Test)

Example 3 with InstanceGroupRequest

use of com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest in project cloudbreak by hortonworks.

the class StackCreationTest method testStackCreation.

@Test
@Parameters({ "stackName", "region", "onFailureAction", "threshold", "adjustmentType", "variant", "availabilityZone", "persistentStorage", "orchestrator", "userDefinedTags", "publicKeyFile" })
public void testStackCreation(@Optional("testing1") String stackName, @Optional("europe-west1") String region, @Optional("DO_NOTHING") String onFailureAction, @Optional("4") Long threshold, @Optional("EXACT") String adjustmentType, @Optional("") String variant, @Optional String availabilityZone, @Optional String persistentStorage, @Optional("SALT") String orchestrator, @Optional("") String userDefinedTags, @Optional("") String publicKeyFile) throws Exception {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    List<InstanceGroup> instanceGroups = itContext.getContextParam(CloudbreakITContextConstants.TEMPLATE_ID, List.class);
    List<InstanceGroupRequest> igMap = new ArrayList<>();
    for (InstanceGroup ig : instanceGroups) {
        InstanceGroupRequest instanceGroupRequest = new InstanceGroupRequest();
        instanceGroupRequest.setGroup(ig.getName());
        instanceGroupRequest.setNodeCount(ig.getNodeCount());
        instanceGroupRequest.setTemplateId(Long.valueOf(ig.getTemplateId()));
        instanceGroupRequest.setType(InstanceGroupType.valueOf(ig.getType()));
        instanceGroupRequest.setSecurityGroupId(Long.valueOf(itContext.getContextParam(CloudbreakITContextConstants.SECURITY_GROUP_ID)));
        igMap.add(instanceGroupRequest);
    }
    String credentialId = itContext.getContextParam(CloudbreakITContextConstants.CREDENTIAL_ID);
    String networkId = itContext.getContextParam(CloudbreakITContextConstants.NETWORK_ID);
    publicKeyFile = StringUtils.hasLength(publicKeyFile) ? publicKeyFile : defaultPublicKeyFile;
    String publicKey = ResourceUtil.readStringFromResource(applicationContext, publicKeyFile).replaceAll("\n", "");
    StackRequest stackRequest = new StackRequest();
    StackAuthenticationRequest stackAuthenticationRequest = new StackAuthenticationRequest();
    stackAuthenticationRequest.setPublicKey(publicKey);
    stackRequest.setStackAuthentication(stackAuthenticationRequest);
    stackRequest.setName(stackName);
    stackRequest.setCredentialId(Long.valueOf(credentialId));
    stackRequest.setRegion(region);
    stackRequest.setOnFailureAction(OnFailureAction.valueOf(onFailureAction));
    FailurePolicyRequest failurePolicyRequest = new FailurePolicyRequest();
    failurePolicyRequest.setAdjustmentType(AdjustmentType.valueOf(adjustmentType));
    failurePolicyRequest.setThreshold(threshold);
    stackRequest.setFailurePolicy(failurePolicyRequest);
    stackRequest.setNetworkId(Long.valueOf(networkId));
    stackRequest.setPlatformVariant(variant);
    stackRequest.setAvailabilityZone(availabilityZone);
    stackRequest.setInstanceGroups(igMap);
    if (!userDefinedTags.isEmpty()) {
        stackRequest.setUserDefinedTags(TagsUtil.getTagsToCheck(userDefinedTags));
    }
    OrchestratorRequest orchestratorRequest = new OrchestratorRequest();
    orchestratorRequest.setType(orchestrator);
    stackRequest.setOrchestrator(orchestratorRequest);
    Map<String, String> map = new HashMap<>();
    if (persistentStorage != null && !persistentStorage.isEmpty()) {
        map.put("persistentStorage", persistentStorage);
    }
    stackRequest.setParameters(map);
    // WHEN
    String stackId = getCloudbreakClient().stackV1Endpoint().postPrivate(stackRequest).getId().toString();
    // THEN
    Assert.assertNotNull(stackId);
    itContext.putCleanUpParam(CloudbreakITContextConstants.STACK_ID, stackId);
    CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackId, "AVAILABLE");
    itContext.putContextParam(CloudbreakITContextConstants.STACK_ID, stackId);
    ScalingUtil.putInstanceCountToContext(itContext, stackId);
}
Also used : IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) StackAuthenticationRequest(com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest) InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StackRequest(com.sequenceiq.cloudbreak.api.model.StackRequest) OrchestratorRequest(com.sequenceiq.cloudbreak.api.model.OrchestratorRequest) FailurePolicyRequest(com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 4 with InstanceGroupRequest

use of com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest in project cloudbreak by hortonworks.

the class StackV2RequestToStackRequestConverter method convert.

@Override
public StackRequest convert(StackV2Request source) {
    StackRequest stackRequest = new StackRequest();
    stackRequest.setName(source.getGeneral().getName());
    if (source.getPlacement() != null) {
        stackRequest.setAvailabilityZone(source.getPlacement().getAvailabilityZone());
        stackRequest.setRegion(source.getPlacement().getRegion());
    }
    stackRequest.setPlatformVariant(source.getPlatformVariant());
    stackRequest.setAmbariVersion(source.getAmbariVersion());
    stackRequest.setHdpVersion(source.getHdpVersion());
    stackRequest.setParameters(convertParameters(source.getParameters()));
    if (source.getCustomDomain() != null) {
        stackRequest.setCustomDomain(source.getCustomDomain().getCustomDomain());
        stackRequest.setCustomHostname(source.getCustomDomain().getCustomHostname());
        stackRequest.setClusterNameAsSubdomain(source.getCustomDomain().isClusterNameAsSubdomain());
        stackRequest.setHostgroupNameAsHostname(source.getCustomDomain().isHostgroupNameAsHostname());
    }
    if (source.getTags() != null) {
        stackRequest.setApplicationTags(source.getTags().getApplicationTags());
        stackRequest.setDefaultTags(source.getTags().getDefaultTags());
        stackRequest.setUserDefinedTags(source.getTags().getUserDefinedTags());
    }
    stackRequest.setInstanceGroups(new ArrayList<>());
    for (InstanceGroupV2Request instanceGroupV2Request : source.getInstanceGroups()) {
        InstanceGroupRequest convert = conversionService.convert(instanceGroupV2Request, InstanceGroupRequest.class);
        stackRequest.getInstanceGroups().add(convert);
    }
    stackRequest.setFailurePolicy(source.getFailurePolicy());
    stackRequest.setStackAuthentication(source.getStackAuthentication());
    stackRequest.setNetwork(conversionService.convert(source.getNetwork(), NetworkRequest.class));
    OrchestratorRequest orchestrator = new OrchestratorRequest();
    orchestrator.setType("SALT");
    stackRequest.setOrchestrator(orchestrator);
    if (source.getImageSettings() != null) {
        stackRequest.setImageCatalog(source.getImageSettings().getImageCatalog());
        stackRequest.setImageId(source.getImageSettings().getImageId());
    }
    stackRequest.setFlexId(source.getFlexId());
    stackRequest.setCredentialName(source.getGeneral().getCredentialName());
    stackRequest.setOwner(Strings.isNullOrEmpty(source.getOwner()) ? authenticatedUserService.getCbUser().getUserId() : source.getOwner());
    stackRequest.setAccount(Strings.isNullOrEmpty(source.getAccount()) ? authenticatedUserService.getCbUser().getAccount() : source.getAccount());
    stackRequest.setOwnerEmail(Strings.isNullOrEmpty(source.getOwnerEmail()) ? authenticatedUserService.getCbUser().getUsername() : source.getOwnerEmail());
    convertClusterRequest(source, stackRequest);
    stackRequest.setCloudPlatform(credentialService.get(stackRequest.getCredentialName(), stackRequest.getAccount()).cloudPlatform());
    return stackRequest;
}
Also used : InstanceGroupV2Request(com.sequenceiq.cloudbreak.api.model.v2.InstanceGroupV2Request) InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) OrchestratorRequest(com.sequenceiq.cloudbreak.api.model.OrchestratorRequest) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) StackRequest(com.sequenceiq.cloudbreak.api.model.StackRequest)

Example 5 with InstanceGroupRequest

use of com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest in project cloudbreak by hortonworks.

the class InstanceGroupV2RequestToInstanceGroupRequestConverter method convert.

@Override
public InstanceGroupRequest convert(InstanceGroupV2Request instanceGroupV2Request) {
    InstanceGroupRequest instanceGroupRequest = new InstanceGroupRequest();
    instanceGroupRequest.setTemplate(getConversionService().convert(instanceGroupV2Request.getTemplate(), TemplateRequest.class));
    instanceGroupRequest.setSecurityGroup(getConversionService().convert(instanceGroupV2Request.getSecurityGroup(), SecurityGroupRequest.class));
    instanceGroupRequest.setGroup(instanceGroupV2Request.getGroup());
    instanceGroupRequest.setNodeCount(instanceGroupV2Request.getNodeCount());
    instanceGroupRequest.setParameters(instanceGroupV2Request.getParameters());
    instanceGroupRequest.setType(instanceGroupV2Request.getType());
    return instanceGroupRequest;
}
Also used : InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) TemplateRequest(com.sequenceiq.cloudbreak.api.model.TemplateRequest) SecurityGroupRequest(com.sequenceiq.cloudbreak.api.model.SecurityGroupRequest)

Aggregations

InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)10 CloudbreakDetailsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakDetailsJson)5 CredentialResponse (com.sequenceiq.cloudbreak.api.model.CredentialResponse)5 ImageJson (com.sequenceiq.cloudbreak.api.model.ImageJson)5 OrchestratorResponse (com.sequenceiq.cloudbreak.api.model.OrchestratorResponse)5 StackAuthenticationResponse (com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse)5 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)5 Test (org.junit.Test)5 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)5 ClusterResponse (com.sequenceiq.cloudbreak.api.model.ClusterResponse)4 FailurePolicyResponse (com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse)4 NetworkResponse (com.sequenceiq.cloudbreak.api.model.NetworkResponse)4 OrchestratorRequest (com.sequenceiq.cloudbreak.api.model.OrchestratorRequest)3 StackRequest (com.sequenceiq.cloudbreak.api.model.StackRequest)3 FailurePolicyRequest (com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest)2 StackAuthenticationRequest (com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest)2 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Parameters (org.testng.annotations.Parameters)2