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;
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations