Search in sources :

Example 1 with StackAuthentication

use of com.sequenceiq.cloudbreak.domain.StackAuthentication in project cloudbreak by hortonworks.

the class StackRequestToStackConverterTest method testConvertWithLoginUserName.

@Test
public void testConvertWithLoginUserName() throws CloudbreakException {
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    when(instanceGroup.getInstanceGroupType()).thenReturn(InstanceGroupType.GATEWAY);
    // GIVEN
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
    given(conversionService.convert(any(StackAuthenticationRequest.class), eq(StackAuthentication.class))).willReturn(new StackAuthentication());
    given(conversionService.convert(any(FailurePolicyRequest.class), eq(FailurePolicy.class))).willReturn(new FailurePolicy());
    given(conversionService.convert(any(InstanceGroupRequest.class), eq(InstanceGroup.class))).willReturn(instanceGroup);
    given(conversionService.convert(any(OrchestratorRequest.class), eq(Orchestrator.class))).willReturn(new Orchestrator());
    given(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).willReturn(OrchestratorType.HOST);
    given(orchestratorTypeResolver.resolveType(any(String.class))).willReturn(OrchestratorType.HOST);
    given(defaultCostTaggingService.prepareDefaultTags(any(String.class), any(String.class), anyMap(), anyString())).willReturn(new HashMap<>());
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("You can not modify the default user!");
    // WHEN
    Stack stack = underTest.convert(getRequest("stack/stack-with-loginusername.json"));
    // THEN
    assertAllFieldsNotNull(stack, Arrays.asList("description", "statusReason", "cluster", "credential", "gatewayPort", "template", "network", "securityConfig", "securityGroup", "version", "created", "platformVariant", "cloudPlatform", "saltPassword", "stackTemplate", "flexSubscription", "datalakeId", "customHostname", "customDomain", "clusterNameAsSubdomain", "hostgroupNameAsHostname", "loginUserName"));
    Assert.assertEquals("eu-west-1", stack.getRegion());
}
Also used : StackAuthenticationRequest(com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) Matchers.anyString(org.mockito.Matchers.anyString) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.Stack) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) OrchestratorRequest(com.sequenceiq.cloudbreak.api.model.OrchestratorRequest) FailurePolicyRequest(com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Test(org.junit.Test)

Example 2 with StackAuthentication

use of com.sequenceiq.cloudbreak.domain.StackAuthentication in project cloudbreak by hortonworks.

the class StackRequestToStackConverterTest method testConvert.

@Test
public void testConvert() throws CloudbreakException {
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    when(instanceGroup.getInstanceGroupType()).thenReturn(InstanceGroupType.GATEWAY);
    // GIVEN
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
    given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<>(Collections.singletonList(instanceGroup)));
    given(conversionService.convert(any(StackAuthenticationRequest.class), eq(StackAuthentication.class))).willReturn(new StackAuthentication());
    given(conversionService.convert(any(FailurePolicyRequest.class), eq(FailurePolicy.class))).willReturn(new FailurePolicy());
    given(conversionService.convert(any(InstanceGroupRequest.class), eq(InstanceGroup.class))).willReturn(instanceGroup);
    given(conversionService.convert(any(OrchestratorRequest.class), eq(Orchestrator.class))).willReturn(new Orchestrator());
    given(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).willReturn(OrchestratorType.HOST);
    given(orchestratorTypeResolver.resolveType(any(String.class))).willReturn(OrchestratorType.HOST);
    given(defaultCostTaggingService.prepareDefaultTags(any(String.class), any(String.class), anyMap(), anyString())).willReturn(new HashMap<>());
    // WHEN
    Stack stack = underTest.convert(getRequest("stack/stack.json"));
    // THEN
    assertAllFieldsNotNull(stack, Arrays.asList("description", "statusReason", "cluster", "credential", "gatewayPort", "template", "network", "securityConfig", "securityGroup", "version", "created", "platformVariant", "cloudPlatform", "saltPassword", "stackTemplate", "flexSubscription", "datalakeId", "customHostname", "customDomain", "clusterNameAsSubdomain", "hostgroupNameAsHostname", "loginUserName", "parameters"));
    Assert.assertEquals("YARN", stack.getRegion());
}
Also used : StackAuthenticationRequest(com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) Matchers.anyString(org.mockito.Matchers.anyString) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.Stack) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) OrchestratorRequest(com.sequenceiq.cloudbreak.api.model.OrchestratorRequest) FailurePolicyRequest(com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Test(org.junit.Test)

Example 3 with StackAuthentication

use of com.sequenceiq.cloudbreak.domain.StackAuthentication in project cloudbreak by hortonworks.

the class StackToStackResponseConverterTest method createSource.

@Override
public Stack createSource() {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster(TestUtil.blueprint(), stack, 1L);
    stack.setCluster(cluster);
    stack.setAvailabilityZone("avZone");
    Network network = new Network();
    network.setId(1L);
    stack.setNetwork(network);
    stack.setFailurePolicy(new FailurePolicy());
    Orchestrator orchestrator = new Orchestrator();
    orchestrator.setId(1L);
    orchestrator.setApiEndpoint("endpoint");
    orchestrator.setType("type");
    stack.setOrchestrator(orchestrator);
    stack.setParameters(new HashMap<>());
    stack.setCloudPlatform("OPENSTACK");
    stack.setGatewayPort(9443);
    stack.setCustomDomain("custom.domain");
    stack.setCustomHostname("hostname");
    stack.setStackAuthentication(new StackAuthentication());
    stack.getStackAuthentication().setPublicKey("rsakey");
    stack.getStackAuthentication().setLoginUserName("cloudbreak");
    stack.setHostgroupNameAsHostname(false);
    stack.setClusterNameAsSubdomain(false);
    Resource s3ArnResource = new Resource(ResourceType.S3_ACCESS_ROLE_ARN, "s3Arn", stack);
    stack.setResources(Collections.singleton(s3ArnResource));
    return stack;
}
Also used : StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) Network(com.sequenceiq.cloudbreak.domain.Network) Resource(com.sequenceiq.cloudbreak.domain.Resource) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 4 with StackAuthentication

use of com.sequenceiq.cloudbreak.domain.StackAuthentication in project cloudbreak by hortonworks.

the class StackRequestToStackConverter method convert.

@Override
public Stack convert(StackRequest source) {
    Stack stack = new Stack();
    stack.setName(source.getName());
    stack.setDisplayName(source.getName());
    stack.setRegion(getRegion(source));
    setPlatform(source);
    stack.setCloudPlatform(source.getCloudPlatform());
    Map<String, String> sourceTags = source.getApplicationTags();
    stack.setTags(getTags(mergeTags(sourceTags, source.getUserDefinedTags(), getDefaultTags(source))));
    if (sourceTags != null && sourceTags.get("datalakeId") != null) {
        stack.setDatalakeId(Long.valueOf(String.valueOf(sourceTags.get("datalakeId"))));
    }
    StackAuthentication stackAuthentication = conversionService.convert(source.getStackAuthentication(), StackAuthentication.class);
    stack.setStackAuthentication(stackAuthentication);
    validateStackAuthentication(source);
    stack.setOwner(source.getOwner());
    stack.setAvailabilityZone(source.getAvailabilityZone());
    stack.setOnFailureActionAction(source.getOnFailureAction());
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED.getStatus(), "", DetailedStackStatus.PROVISION_REQUESTED));
    stack.setFailurePolicy(getConversionService().convert(source.getFailurePolicy(), FailurePolicy.class));
    stack.setCreated(Calendar.getInstance().getTimeInMillis());
    stack.setPlatformVariant(source.getPlatformVariant());
    stack.setOrchestrator(getConversionService().convert(source.getOrchestrator(), Orchestrator.class));
    if (source.getCredential() != null) {
        stack.setCredential(getConversionService().convert(source.getCredential(), Credential.class));
    }
    Set<InstanceGroup> instanceGroups = convertInstanceGroups(source, stack);
    stack.setInstanceGroups(instanceGroups);
    if (source.getNetwork() != null) {
        stack.setNetwork(getConversionService().convert(source.getNetwork(), Network.class));
    }
    stack.setCustomDomain(source.getCustomDomain());
    stack.setCustomHostname(source.getCustomHostname());
    stack.setClusterNameAsSubdomain(source.isClusterNameAsSubdomain());
    stack.setHostgroupNameAsHostname(source.isHostgroupNameAsHostname());
    stack.setUuid(UUID.randomUUID().toString());
    return stack;
}
Also used : StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) Credential(com.sequenceiq.cloudbreak.domain.Credential) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) Network(com.sequenceiq.cloudbreak.domain.Network) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 5 with StackAuthentication

use of com.sequenceiq.cloudbreak.domain.StackAuthentication in project cloudbreak by hortonworks.

the class InstanceMetaDataToCloudInstanceConverter method convert.

@Override
public CloudInstance convert(InstanceMetaData metaDataEnity) {
    InstanceGroup group = metaDataEnity.getInstanceGroup();
    Template template = metaDataEnity.getInstanceGroup().getTemplate();
    StackAuthentication stackAuthentication = group.getStack().getStackAuthentication();
    InstanceStatus status = getInstanceStatus(metaDataEnity);
    InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEnity.getPrivateId(), status);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.getPublicKey(), stackAuthentication.getPublicKeyId(), stackAuthentication.getLoginUserName());
    Map<String, Object> params = new HashMap<>();
    params.put(CloudInstance.SUBNET_ID, metaDataEnity.getSubnetId());
    return new CloudInstance(metaDataEnity.getInstanceId(), instanceTemplate, instanceAuthentication, params);
}
Also used : StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)8 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)6 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)6 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)6 Stack (com.sequenceiq.cloudbreak.domain.Stack)5 FailurePolicyRequest (com.sequenceiq.cloudbreak.api.model.FailurePolicyRequest)4 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)4 OrchestratorRequest (com.sequenceiq.cloudbreak.api.model.OrchestratorRequest)4 StackAuthenticationRequest (com.sequenceiq.cloudbreak.api.model.StackAuthenticationRequest)4 Test (org.junit.Test)4 Matchers.anyString (org.mockito.Matchers.anyString)4 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)4 Network (com.sequenceiq.cloudbreak.domain.Network)2 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)1 StackRequest (com.sequenceiq.cloudbreak.api.model.StackRequest)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)1 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1