use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class OpenStackInstanceBuilder method executeAction.
private CloudVmInstanceStatus executeAction(AuthenticatedContext auth, CloudInstance instance, Action action) {
OSClient<?> osClient = createOSClient(auth);
ActionResponse actionResponse = osClient.compute().servers().action(instance.getInstanceId(), action);
if (actionResponse.isSuccess()) {
return new CloudVmInstanceStatus(instance, InstanceStatus.IN_PROGRESS);
}
return new CloudVmInstanceStatus(instance, InstanceStatus.FAILED, actionResponse.getFault());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class OpenStackInstanceBuilder method checkInstances.
@Override
public List<CloudVmInstanceStatus> checkInstances(OpenStackContext context, AuthenticatedContext auth, List<CloudInstance> instances) {
List<CloudVmInstanceStatus> statuses = Lists.newArrayList();
OSClient<?> osClient = createOSClient(auth);
for (CloudInstance instance : instances) {
Server server = osClient.compute().servers().get(instance.getInstanceId());
if (server == null) {
statuses.add(new CloudVmInstanceStatus(instance, InstanceStatus.TERMINATED));
} else {
statuses.add(new CloudVmInstanceStatus(instance, NovaInstanceStatus.get(server)));
}
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class OpenStackInstanceConnector method executeAction.
private List<CloudVmInstanceStatus> executeAction(AuthenticatedContext ac, Iterable<CloudInstance> cloudInstances, Action action) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
OSClient<?> osClient = openStackClient.createOSClient(ac);
for (CloudInstance cloudInstance : cloudInstances) {
ActionResponse actionResponse = osClient.compute().servers().action(cloudInstance.getInstanceId(), action);
if (actionResponse.isSuccess()) {
statuses.add(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS));
} else {
statuses.add(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.FAILED, actionResponse.getFault()));
}
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class OpenStackNativeMetaDataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
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);
List<CloudVmMetaDataStatus> results = new ArrayList<>();
for (CloudResource resource : resources) {
if (resource.getType() == ResourceType.OPENSTACK_INSTANCE) {
String instanceUUID = resource.getReference();
Server server = client.compute().servers().get(instanceUUID);
if (server != null) {
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;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class MockInstanceConnector method stop.
@Override
public List<CloudVmInstanceStatus> stop(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
for (CloudInstance instance : vms) {
CloudVmInstanceStatus instanceStatus = new CloudVmInstanceStatus(instance, InstanceStatus.STOPPED);
cloudVmInstanceStatuses.add(instanceStatus);
}
return cloudVmInstanceStatuses;
}
Aggregations