use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential 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.CloudCredential in project cloudbreak by hortonworks.
the class GcpContextBuilder method contextInit.
@Override
public GcpContext contextInit(CloudContext context, AuthenticatedContext auth, Network network, List<CloudResource> resources, boolean build) {
CloudCredential credential = auth.getCloudCredential();
String projectId = GcpStackUtil.getProjectId(credential);
String serviceAccountId = GcpStackUtil.getServiceAccountId(credential);
Compute compute = GcpStackUtil.buildCompute(credential);
Location location = context.getLocation();
boolean noPublicIp = network != null ? GcpStackUtil.noPublicIp(network) : false;
return new GcpContext(context.getName(), location, projectId, serviceAccountId, compute, noPublicIp, PARALLEL_RESOURCE_REQUEST, build);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class GetTlsInfoHandler method accept.
@Override
public void accept(Event<GetTlsInfoRequest> getTlsInfoRequestEvent) {
LOGGER.info("Received event: {}", getTlsInfoRequestEvent);
GetTlsInfoRequest<?> tlsInfoRequest = getTlsInfoRequestEvent.getData();
try {
CloudContext cloudContext = tlsInfoRequest.getCloudContext();
CloudCredential cloudCredential = tlsInfoRequest.getCloudCredential();
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
CloudStack cloudStack = tlsInfoRequest.getCloudStack();
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
TlsInfo tlsInfo = connector.resources().getTlsInfo(ac, cloudStack);
GetTlsInfoResult getTlsInfoResult = new GetTlsInfoResult(tlsInfoRequest, tlsInfo);
tlsInfoRequest.getResult().onNext(getTlsInfoResult);
eventBus.notify(getTlsInfoResult.selector(), new Event<>(getTlsInfoRequestEvent.getHeaders(), getTlsInfoResult));
LOGGER.info("GetTlsInfoHandler finished.");
} catch (RuntimeException e) {
String errorMsg = "Failed to get Tls info from cloud connector!";
LOGGER.error(errorMsg, e);
GetTlsInfoResult failure = new GetTlsInfoResult(errorMsg, e, tlsInfoRequest);
tlsInfoRequest.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(getTlsInfoRequestEvent.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class CredentialToCloudCredentialConverter method convert.
public CloudCredential convert(Credential credential) {
if (credential == null) {
return null;
}
Json attributes = credential.getAttributes();
Map<String, Object> fields = attributes == null ? Collections.emptyMap() : attributes.getMap();
fields = definitionService.revertProperties(platform(credential.cloudPlatform()), fields);
fields.put(CREDENTIAL_ID, credential.getId());
return new CloudCredential(credential.getId(), credential.getName(), fields);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method removeInstances.
public Set<String> removeInstances(Stack stack, Set<String> instanceIds, String instanceGroup) {
LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
List<CloudInstance> instances = new ArrayList<>();
InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(instanceGroup);
for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
if (instanceIds.contains(metaData.getInstanceId())) {
CloudInstance cloudInstance = metadataConverter.convert(metaData);
instances.add(cloudInstance);
}
}
CloudStack cloudStack = cloudStackConverter.convertForDownscale(stack, instanceIds);
DownscaleStackRequest downscaleRequest = new DownscaleStackRequest(cloudContext, cloudCredential, cloudStack, resources, instances);
LOGGER.info("Triggering downscale stack event: {}", downscaleRequest);
eventBus.notify(downscaleRequest.selector(), eventFactory.createEvent(downscaleRequest));
try {
DownscaleStackResult res = downscaleRequest.await();
LOGGER.info("Downscale stack result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to downscale the stack", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return instanceIds;
} catch (InterruptedException e) {
LOGGER.error("Error while downscaling the stack", e);
throw new OperationException(e);
}
}
Aggregations