Search in sources :

Example 41 with CloudVmMetaDataStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus in project cloudbreak by hortonworks.

the class AwsMetaDataCollectorTest method collectNewAndExistingOneGroup.

@Test
public void collectNewAndExistingOneGroup() {
    List<CloudInstance> vms = new ArrayList<>();
    List<Volume> volumes = new ArrayList<>();
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    vms.add(new CloudInstance(null, new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
    vms.add(new CloudInstance("i-1", new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
    when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);
    when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway"))).thenReturn("cbgateway-AAA");
    List<String> gatewayIds = Arrays.asList("i-1", "i-2");
    when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA"))).thenReturn(gatewayIds);
    when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);
    when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);
    Instance instance1 = Mockito.mock(Instance.class);
    when(instance1.getInstanceId()).thenReturn("i-1");
    when(instance1.getPrivateIpAddress()).thenReturn("privateIp1");
    when(instance1.getPublicIpAddress()).thenReturn("publicIp1");
    Instance instance2 = Mockito.mock(Instance.class);
    when(instance2.getInstanceId()).thenReturn("i-2");
    when(instance2.getPrivateIpAddress()).thenReturn("privateIp2");
    when(instance2.getPublicIpAddress()).thenReturn("publicIp2");
    List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance1, instance2));
    when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);
    AuthenticatedContext ac = authenticatedContext();
    List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);
    verify(amazonEC2Client, times(2)).createTags(any(CreateTagsRequest.class));
    Assert.assertEquals(2, statuses.size());
    Assert.assertEquals("i-1", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
    Assert.assertEquals("privateIp1", statuses.get(0).getMetaData().getPrivateIp());
    Assert.assertEquals("publicIp1", statuses.get(0).getMetaData().getPublicIp());
    Assert.assertEquals("i-2", statuses.get(1).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
    Assert.assertEquals("privateIp2", statuses.get(1).getMetaData().getPrivateIp());
    Assert.assertEquals("publicIp2", statuses.get(1).getMetaData().getPublicIp());
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) Reservation(com.amazonaws.services.ec2.model.Reservation) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.Test)

Example 42 with CloudVmMetaDataStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus in project cloudbreak by hortonworks.

the class SaltApiRunPostResponse method saltUtilSyncGrainsResponse.

protected Object saltUtilSyncGrainsResponse() throws JsonProcessingException {
    ApplyResponse applyResponse = new ApplyResponse();
    List<Map<String, Object>> responseList = new ArrayList<>();
    Map<String, Object> hostMap = new HashMap<>();
    for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
        CloudVmMetaDataStatus cloudVmMetaDataStatus = stringCloudVmMetaDataStatusEntry.getValue();
        if (InstanceStatus.STARTED == cloudVmMetaDataStatus.getCloudVmInstanceStatus().getStatus()) {
            String privateIp = cloudVmMetaDataStatus.getMetaData().getPrivateIp();
            hostMap.put("host-" + privateIp.replace(".", "-"), privateIp);
        }
    }
    responseList.add(hostMap);
    applyResponse.setResult(responseList);
    return objectMapper.writeValueAsString(applyResponse);
}
Also used : HashMap(java.util.HashMap) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse)

Example 43 with CloudVmMetaDataStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus in project cloudbreak by hortonworks.

the class CloudMetaDataStatuses method createCloudVmMetaDataStatuses.

private List<CloudVmMetaDataStatus> createCloudVmMetaDataStatuses(Collection<CloudInstance> cloudInstances) {
    List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
    for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
        CloudVmMetaDataStatus oldCloudVmMetaDataStatus = stringCloudVmMetaDataStatusEntry.getValue();
        InstanceTemplate oldTemplate = oldCloudVmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance().getTemplate();
        Optional<CloudInstance> cloudInstance = cloudInstances.stream().filter(instance -> Objects.equals(instance.getTemplate().getPrivateId(), oldTemplate.getPrivateId())).findFirst();
        if (cloudInstance.isPresent()) {
            CloudInstance newCloudInstance = new CloudInstance(stringCloudVmMetaDataStatusEntry.getKey(), cloudInstance.get().getTemplate(), cloudInstance.get().getAuthentication(), cloudInstance.get().getParameters());
            CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(newCloudInstance, oldCloudVmMetaDataStatus.getCloudVmInstanceStatus().getStatus());
            CloudVmMetaDataStatus newCloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, oldCloudVmMetaDataStatus.getMetaData());
            cloudVmMetaDataStatuses.add(newCloudVmMetaDataStatus);
        }
    }
    return cloudVmMetaDataStatuses;
}
Also used : Collection(java.util.Collection) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TypeToken(com.google.common.reflect.TypeToken) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Gson(com.google.gson.Gson) Map(java.util.Map) Entry(java.util.Map.Entry) ITResponse(com.sequenceiq.it.spark.ITResponse) Optional(java.util.Optional) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)43 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)20 ArrayList (java.util.ArrayList)18 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)13 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)12 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)10 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)9 Service (spark.Service)8 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Map (java.util.Map)7 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)6 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)6 Instance (com.amazonaws.services.ec2.model.Instance)6 Reservation (com.amazonaws.services.ec2.model.Reservation)6 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 AmbariClusterResponse (com.sequenceiq.it.spark.ambari.AmbariClusterResponse)6 EmptyAmbariResponse (com.sequenceiq.it.spark.ambari.EmptyAmbariResponse)6 CreateTagsRequest (com.amazonaws.services.ec2.model.CreateTagsRequest)5 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)5