use of com.sequenceiq.cloudbreak.cloud.model.InstanceStatus in project cloudbreak by hortonworks.
the class MockInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext authenticatedContext, List<CloudInstance> vms) {
try {
MockCredentialView mockCredentialView = mockCredentialViewFactory.createCredetialView(authenticatedContext.getCloudCredential());
LOGGER.info("collect instance statuses from mock spi, server address: " + mockCredentialView.getMockEndpoint());
CloudVmInstanceStatus[] cloudVmInstanceStatusArray = Unirest.post(mockCredentialView.getMockEndpoint() + "/spi/cloud_instance_statuses").asObject(CloudVmInstanceStatus[].class).getBody();
LOGGER.info("collected instance statuses: " + Arrays.toString(cloudVmInstanceStatusArray));
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
for (CloudInstance instance : vms) {
Optional<CloudVmInstanceStatus> vmInstanceStatusFromApi = Arrays.stream(cloudVmInstanceStatusArray).filter(instanceStatus -> instanceStatus.getCloudInstance().getTemplate().getPrivateId().equals(instance.getTemplate().getPrivateId())).findFirst();
InstanceStatus instanceStatus = InstanceStatus.TERMINATED;
if (vmInstanceStatusFromApi.isPresent()) {
instanceStatus = vmInstanceStatusFromApi.get().getStatus();
}
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(instance, instanceStatus);
cloudVmInstanceStatuses.add(cloudVmInstanceStatus);
}
return cloudVmInstanceStatuses;
} catch (UnirestException e) {
throw new RuntimeException("can't convert to object", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStatus in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildInstanceGroups.
public List<Group> buildInstanceGroups(List<InstanceGroup> instanceGroups, StackAuthentication stackAuthentication, Collection<String> deleteRequests) {
// sort by name to avoid shuffling the different instance groups
Collections.sort(instanceGroups);
List<Group> groups = new ArrayList<>();
long privateId = getFirstValidPrivateId(instanceGroups);
for (InstanceGroup instanceGroup : instanceGroups) {
if (instanceGroup.getTemplate() != null) {
CloudInstance skeleton = null;
List<CloudInstance> instances = new ArrayList<>();
Template template = instanceGroup.getTemplate();
int desiredNodeCount = instanceGroup.getNodeCount();
// existing instances
for (InstanceMetaData metaData : instanceGroup.getInstanceMetaData()) {
InstanceStatus status = getInstanceStatus(metaData, deleteRequests);
instances.add(buildInstance(metaData, template, stackAuthentication, instanceGroup.getGroupName(), metaData.getPrivateId(), status));
}
// new instances
int existingNodesSize = instances.size();
if (existingNodesSize < desiredNodeCount) {
for (long i = 0; i < desiredNodeCount - existingNodesSize; i++) {
instances.add(buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), privateId++, InstanceStatus.CREATE_REQUESTED));
}
}
if (existingNodesSize == desiredNodeCount && desiredNodeCount == 0) {
skeleton = buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), 0L, InstanceStatus.CREATE_REQUESTED);
}
Json attributes = instanceGroup.getAttributes();
InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stackAuthentication);
Map<String, Object> fields = attributes == null ? Collections.emptyMap() : attributes.getMap();
groups.add(new Group(instanceGroup.getGroupName(), instanceGroup.getInstanceGroupType(), instances, buildSecurity(instanceGroup), skeleton, fields, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
}
}
return groups;
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStatus in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilder method checkInstances.
@Override
public List<CloudVmInstanceStatus> checkInstances(GcpContext context, AuthenticatedContext auth, List<CloudInstance> instances) {
CloudInstance cloudInstance = instances.get(0);
try {
LOGGER.info("Checking instance: {}", cloudInstance);
Operation operation = check(context, cloudInstance);
boolean finished = operation == null || GcpStackUtil.isOperationFinished(operation);
InstanceStatus status = finished ? context.isBuild() ? InstanceStatus.STARTED : InstanceStatus.STOPPED : InstanceStatus.IN_PROGRESS;
LOGGER.info("Instance: {} status: {}", instances, status);
return Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, status));
} catch (Exception ignored) {
LOGGER.info("Failed to check instance state of {}", cloudInstance);
return Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStatus in project cloudbreak by hortonworks.
the class GcpInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
CloudCredential credential = ac.getCloudCredential();
CloudContext cloudContext = ac.getCloudContext();
Compute compute = GcpStackUtil.buildCompute(credential);
for (CloudInstance instance : vms) {
InstanceStatus status = InstanceStatus.UNKNOWN;
try {
Instance executeInstance = getInstance(cloudContext, credential, compute, instance.getInstanceId());
if ("RUNNING".equals(executeInstance.getStatus())) {
status = InstanceStatus.STARTED;
} else if ("TERMINATED".equals(executeInstance.getStatus())) {
status = InstanceStatus.STOPPED;
}
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
status = InstanceStatus.TERMINATED;
} else {
LOGGER.warn(String.format("Instance %s is not reachable", instance), e);
}
} catch (IOException e) {
LOGGER.warn(String.format("Instance %s is not reachable", instance), e);
}
statuses.add(new CloudVmInstanceStatus(instance, status));
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStatus 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);
}
Aggregations