use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class MockServer method addInstance.
public void addInstance(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.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class AzureInstanceConnector method start.
@Override
public List<CloudVmInstanceStatus> start(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) {
String stackName = armTemplateUtils.getStackName(ac.getCloudContext());
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
for (CloudInstance vm : vms) {
try {
AzureClient azureClient = ac.getParameter(AzureClient.class);
azureClient.startVirtualMachine(stackName, vm.getInstanceId());
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.IN_PROGRESS));
} catch (RuntimeException e) {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.FAILED, e.getMessage()));
}
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class AzureInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
String stackName = armTemplateUtils.getStackName(ac.getCloudContext());
for (CloudInstance vm : vms) {
try {
AzureClient azureClient = ac.getParameter(AzureClient.class);
boolean virtualMachineExists = azureClient.isVirtualMachineExists(stackName, vm.getInstanceId());
if (virtualMachineExists) {
PowerState virtualMachinePowerState = azureClient.getVirtualMachinePowerState(stackName, vm.getInstanceId());
statuses.add(new CloudVmInstanceStatus(vm, AzureInstanceStatus.get(virtualMachinePowerState)));
} else {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
}
} catch (CloudException e) {
if (e.body() != null && "ResourceNotFound".equals(e.body().code())) {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
} else {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.UNKNOWN));
}
} catch (RuntimeException ignored) {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.UNKNOWN));
}
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class CloudMetaDataStatuses method createCloudVmMetaDataStatuses.
private List<CloudVmMetaDataStatus> createCloudVmMetaDataStatuses(Collection<CloudInstance> cloudInstances) {
List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
CloudVmMetaDataStatus oldCloudVmMetaDataStatus = stringCloudVmMetaDataStatusEntry.getValue();
InstanceTemplate oldTemplate = oldCloudVmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance().getTemplate();
Optional<CloudInstance> cloudInstance = cloudInstances.stream().filter(instance -> Objects.equals(instance.getTemplate().getPrivateId(), oldTemplate.getPrivateId())).findFirst();
if (cloudInstance.isPresent()) {
CloudInstance newCloudInstance = new CloudInstance(stringCloudVmMetaDataStatusEntry.getKey(), cloudInstance.get().getTemplate(), cloudInstance.get().getAuthentication(), cloudInstance.get().getParameters());
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(newCloudInstance, oldCloudVmMetaDataStatus.getCloudVmInstanceStatus().getStatus());
CloudVmMetaDataStatus newCloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, oldCloudVmMetaDataStatus.getMetaData());
cloudVmMetaDataStatuses.add(newCloudVmMetaDataStatus);
}
}
return cloudVmMetaDataStatuses;
}
Aggregations