use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance 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.CloudInstance 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.CloudInstance in project cloudbreak by hortonworks.
the class OpenStackResourceConnector method removeDeleteRequestedInstances.
private CloudStack removeDeleteRequestedInstances(CloudStack stack) {
List<Group> groups = new ArrayList<>(stack.getGroups().size());
for (Group group : stack.getGroups()) {
List<CloudInstance> instances = new ArrayList<>(group.getInstances());
for (CloudInstance instance : group.getInstances()) {
if (InstanceStatus.DELETE_REQUESTED == instance.getTemplate().getStatus()) {
instances.remove(instance);
}
}
groups.add(new Group(group.getName(), group.getType(), instances, group.getSecurity(), null, stack.getInstanceAuthentication(), stack.getInstanceAuthentication().getLoginUserName(), stack.getInstanceAuthentication().getPublicKey()));
}
return new CloudStack(groups, stack.getNetwork(), stack.getImage(), stack.getParameters(), stack.getTags(), stack.getTemplate(), stack.getInstanceAuthentication(), stack.getInstanceAuthentication().getLoginUserName(), stack.getInstanceAuthentication().getPublicKey());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance in project cloudbreak by hortonworks.
the class OpenStackFlavorVerifierTest method createGroup.
private Group createGroup(String flavor) {
InstanceTemplate template = new InstanceTemplate(flavor, null, null, new ArrayList<>(), null, null, null);
CloudInstance skeleton = new CloudInstance("id1", template, null);
Group group = new Group("name", InstanceGroupType.GATEWAY, new ArrayList<>(), null, skeleton, null, "loginUserName", "publicKey");
return group;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudInstance 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;
}
Aggregations