use of com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData 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.CloudInstanceMetaData 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.CloudInstanceMetaData 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;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData in project cloudbreak by hortonworks.
the class MockInstanceUtil method addInstance.
public void addInstance(Map<String, CloudVmMetaDataStatus> instanceMap, int numberOfAddedInstances) {
ServerAddressGenerator serverAddressGenerator = new ServerAddressGenerator(numberOfAddedInstances);
serverAddressGenerator.setFrom(instanceMap.size());
serverAddressGenerator.iterateOver((address, number) -> {
String instanceId = "instance-" + address;
InstanceTemplate instanceTemplate = new InstanceTemplate("medium", "group", Integer.toUnsignedLong(number), new ArrayList<>(), InstanceStatus.CREATED, null, 0L);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
CloudInstance cloudInstanceWithId = new CloudInstance(instanceId, instanceTemplate, instanceAuthentication);
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstanceWithId, InstanceStatus.STARTED);
CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(address, mockServerAddress, sshPort, "MOCK");
CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
instanceMap.put(instanceId, cloudVmMetaDataStatus);
});
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData in project cloudbreak by hortonworks.
the class OpenStackMetadataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
CloudResource resource = utils.getHeatResource(resources);
String stackName = utils.getStackName(authenticatedContext);
String heatStackId = resource.getName();
List<InstanceTemplate> templates = Lists.transform(vms, CloudInstance::getTemplate);
Map<String, InstanceTemplate> templateMap = Maps.uniqueIndex(templates, from -> utils.getPrivateInstanceId(from.getGroupName(), Long.toString(from.getPrivateId())));
OSClient<?> client = openStackClient.createOSClient(authenticatedContext);
Stack heatStack = client.heat().stacks().getDetails(stackName, heatStackId);
List<CloudVmMetaDataStatus> results = new ArrayList<>();
List<Map<String, Object>> outputs = heatStack.getOutputs();
for (Map<String, Object> map : outputs) {
String instanceUUID = (String) map.get("output_value");
if (!StringUtils.isEmpty(instanceUUID)) {
Server server = client.compute().servers().get(instanceUUID);
Map<String, String> metadata = server.getMetadata();
String privateInstanceId = utils.getPrivateInstanceId(metadata);
InstanceTemplate template = templateMap.get(privateInstanceId);
if (template != null) {
CloudInstanceMetaData md = cloudInstanceMetaDataExtractor.extractMetadata(client, server, instanceUUID);
// TODO use here sshkey
CloudInstance cloudInstance = new CloudInstance(instanceUUID, template, null);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
results.add(new CloudVmMetaDataStatus(status, md));
}
}
}
return results;
}
Aggregations