Search in sources :

Example 26 with CloudVmMetaDataStatus

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

the class TestApplicationContext method cloudConnectors.

@Bean
public CloudConnector cloudConnectors() throws Exception {
    CloudResource resource = new Builder().type(ResourceType.HEAT_STACK).name("ref").build();
    when(cloudConnector.authentication()).thenReturn(authenticator);
    when(cloudConnector.credentials()).thenReturn(credentialConnector);
    when(credentialConnector.create(any(AuthenticatedContext.class))).thenReturn(new CloudCredentialStatus(null, CredentialStatus.CREATED));
    when(credentialConnector.delete(any(AuthenticatedContext.class))).thenReturn(new CloudCredentialStatus(null, CredentialStatus.DELETED));
    when(authenticator.authenticate(any(), any())).thenReturn(g.createAuthenticatedContext());
    when(cloudConnector.platform()).thenReturn(Platform.platform("TESTCONNECTOR"));
    when(cloudConnector.variant()).thenReturn(Variant.variant("TESTVARIANT"));
    when(cloudConnector.resources()).thenReturn(resourceConnector);
    when(cloudConnector.instances()).thenReturn(instanceConnector);
    when(cloudConnector.metadata()).thenReturn(collector);
    when(resourceConnector.launch(any(), any(), any(), any(), anyLong())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.CREATED)));
    when(resourceConnector.terminate(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.DELETED)));
    when(resourceConnector.update(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(resourceConnector.upscale(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(resourceConnector.downscale(any(), any(), any(), anyList(), anyMap())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(instanceConnector.check(any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STARTED)));
    CloudVmInstanceStatus collectInstanceStatus = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS);
    when(collector.collect(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmMetaDataStatus(collectInstanceStatus, new CloudInstanceMetaData("privateIp", "publicIp", "hypervisor"))));
    when(instanceConnector.start(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STARTED)));
    when(instanceConnector.stop(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STOPPED)));
    when(instanceConnector.getConsoleOutput(any(), eq(cloudInstance))).thenReturn(g.getSshFingerprint() + "    RSA/n-----END SSH HOST KEY FINGERPRINTS-----");
    when(instanceConnector.getConsoleOutput(any(), eq(cloudInstanceBad))).thenReturn("XYZ    RSA/n-----END SSH HOST KEY FINGERPRINTS-----");
    return cloudConnector;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Bean(org.springframework.context.annotation.Bean)

Example 27 with CloudVmMetaDataStatus

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

the class AwsMetadataCollector method collect.

@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) {
    List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
    try {
        String region = ac.getCloudContext().getLocation().getRegion().value();
        AmazonCloudFormationClient amazonCFClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), region);
        AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), region);
        AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region);
        // contains all instances
        ListMultimap<String, CloudInstance> groupByInstanceGroup = groupByInstanceGroup(vms);
        for (String key : groupByInstanceGroup.keySet()) {
            List<CloudInstance> cloudInstances = groupByInstanceGroup.get(key);
            cloudVmMetaDataStatuses.addAll(collectGroupMetaData(ac, amazonASClient, amazonEC2Client, amazonCFClient, key, cloudInstances));
        }
        return cloudVmMetaDataStatuses;
    } catch (RuntimeException e) {
        throw new CloudConnectorException(e.getMessage(), e);
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient)

Example 28 with CloudVmMetaDataStatus

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

the class GcpMetadataCollector method collect.

@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
    List<CloudVmMetaDataStatus> instanceMetaData = new ArrayList<>();
    Map<String, CloudResource> instanceNameMap = groupByInstanceName(resources);
    Map<Long, CloudResource> privateIdMap = groupByPrivateId(resources);
    for (CloudInstance cloudInstance : vms) {
        String instanceId = cloudInstance.getInstanceId();
        CloudResource cloudResource;
        cloudResource = instanceId != null ? instanceNameMap.get(instanceId) : privateIdMap.get(cloudInstance.getTemplate().getPrivateId());
        CloudVmMetaDataStatus cloudVmMetaDataStatus = getCloudVmMetaDataStatus(authenticatedContext, cloudResource, cloudInstance);
        instanceMetaData.add(cloudVmMetaDataStatus);
    }
    return instanceMetaData;
}
Also used : CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 29 with CloudVmMetaDataStatus

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

the class YarnMetadataCollector method collect.

@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
    try {
        YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
        CloudResource yarnApplication = getYarnApplcationResource(resources);
        ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
        applicationDetailRequest.setName(yarnApplication.getName());
        ResponseContext responseContext = yarnClient.getApplicationDetail(applicationDetailRequest);
        if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_SUCCESS) {
            ApplicationDetailResponse applicationDetailResponse = (ApplicationDetailResponse) responseContext.getResponseObject();
            ListMultimap<String, CloudInstance> groupInstancesByInstanceGroup = groupInstancesByInstanceGroup(vms);
            ListMultimap<String, Container> groupContainersByInstanceGroup = groupContainersByInstanceGroup(applicationDetailResponse.getContainers());
            List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = Lists.newArrayList();
            for (String groupName : groupContainersByInstanceGroup.keySet()) {
                List<CloudInstance> groupInstances = groupInstancesByInstanceGroup.get(groupName);
                List<Container> groupContainers = groupContainersByInstanceGroup.get(groupName);
                Map<String, CloudInstance> mapByInstanceId = mapByInstanceId(groupInstances);
                Queue<CloudInstance> untrackedInstances = untrackedInstances(groupInstances);
                for (Container container : groupContainers) {
                    String containerId = container.getId();
                    CloudInstance cloudInstance = mapByInstanceId.get(containerId);
                    if (cloudInstance == null) {
                        if (!untrackedInstances.isEmpty()) {
                            cloudInstance = untrackedInstances.remove();
                            cloudInstance = new CloudInstance(containerId, cloudInstance.getTemplate(), cloudInstance.getAuthentication());
                        }
                    }
                    if (cloudInstance != null) {
                        String ipAddress = container.getIp();
                        CloudInstanceMetaData md = new CloudInstanceMetaData(ipAddress, ipAddress);
                        CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
                        CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, md);
                        cloudVmMetaDataStatuses.add(cloudVmMetaDataStatus);
                    }
                }
            }
            return cloudVmMetaDataStatuses;
        } else {
            ApplicationErrorResponse errorResponse = responseContext.getResponseError();
            throw new CloudConnectorException(String.format("Failed to get yarn application details: HTTP Return: %d Error: %s", responseContext.getStatusCode(), errorResponse == null ? "unknown" : errorResponse.getDiagnostics()));
        }
    } catch (MalformedURLException ex) {
        throw new CloudConnectorException("Failed to get yarn application details", ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ApplicationErrorResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationErrorResponse) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient) ApplicationDetailResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationDetailResponse) Container(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Container) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) ApplicationDetailRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.ApplicationDetailRequest) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) ResponseContext(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ResponseContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 30 with CloudVmMetaDataStatus

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

the class MetadataSetupService method saveInstanceMetaData.

public int saveInstanceMetaData(Stack stack, Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatusList, InstanceStatus status) {
    int newInstances = 0;
    boolean ambariServerFound = false;
    Set<InstanceMetaData> allInstanceMetadata = instanceMetaDataRepository.findNotTerminatedForStack(stack.getId());
    boolean primaryIgSelected = allInstanceMetadata.stream().anyMatch(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY);
    for (CloudVmMetaDataStatus cloudVmMetaDataStatus : cloudVmMetaDataStatusList) {
        CloudInstance cloudInstance = cloudVmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance();
        CloudInstanceMetaData md = cloudVmMetaDataStatus.getMetaData();
        long timeInMillis = Calendar.getInstance().getTimeInMillis();
        Long privateId = cloudInstance.getTemplate().getPrivateId();
        String instanceId = cloudInstance.getInstanceId();
        InstanceMetaData instanceMetaDataEntry = createInstanceMetadataIfAbsent(allInstanceMetadata, privateId, instanceId);
        if (instanceMetaDataEntry.getInstanceId() == null) {
            newInstances++;
        }
        // CB 1.0.x clusters do not have private id thus we cannot correlate them with instance groups thus keep the original one
        InstanceGroup ig = instanceMetaDataEntry.getInstanceGroup();
        String group = ig == null ? cloudInstance.getTemplate().getGroupName() : ig.getGroupName();
        InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stack.getId(), group);
        instanceMetaDataEntry.setPrivateIp(md.getPrivateIp());
        instanceMetaDataEntry.setPublicIp(md.getPublicIp());
        instanceMetaDataEntry.setSshPort(md.getSshPort());
        instanceMetaDataEntry.setLocalityIndicator(md.getLocalityIndicator());
        instanceMetaDataEntry.setInstanceGroup(instanceGroup);
        instanceMetaDataEntry.setInstanceId(instanceId);
        instanceMetaDataEntry.setPrivateId(privateId);
        instanceMetaDataEntry.setStartDate(timeInMillis);
        instanceMetaDataEntry.setSubnetId(cloudInstance.getStringParameter(CloudInstance.SUBNET_ID));
        if (instanceMetaDataEntry.getInstanceMetadataType() == null) {
            if (ig != null) {
                if (InstanceGroupType.GATEWAY.equals(ig.getInstanceGroupType())) {
                    if (!primaryIgSelected) {
                        primaryIgSelected = true;
                        instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
                    } else {
                        instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
                    }
                } else {
                    instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.CORE);
                }
            } else {
                instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.CORE);
            }
        }
        if (!ambariServerFound && InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType())) {
            instanceMetaDataEntry.setAmbariServer(Boolean.TRUE);
            ambariServerFound = true;
        } else {
            instanceMetaDataEntry.setAmbariServer(Boolean.FALSE);
        }
        if (status != null) {
            instanceMetaDataEntry.setInstanceStatus(status);
        }
        instanceMetaDataRepository.save(instanceMetaDataEntry);
    }
    return newInstances;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

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