Search in sources :

Example 31 with CloudVmInstanceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.

the class OpenStackInstanceConnector method check.

@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> statuses = new ArrayList<>();
    OSClient<?> osClient = openStackClient.createOSClient(ac);
    for (CloudInstance vm : vms) {
        Optional<Server> server = Optional.ofNullable(vm.getInstanceId()).map(iid -> osClient.compute().servers().get(iid));
        if (server.isPresent()) {
            statuses.add(new CloudVmInstanceStatus(vm, NovaInstanceStatus.get(server.get())));
        } else {
            statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
        }
    }
    return statuses;
}
Also used : Server(org.openstack4j.model.compute.Server) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 32 with CloudVmInstanceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.

the class OpenStackMetadataCollector method collect.

@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
    CloudResource resource = utils.getHeatResource(resources);
    String stackName = utils.getStackName(authenticatedContext);
    String heatStackId = resource.getName();
    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);
    Stack heatStack = client.heat().stacks().getDetails(stackName, heatStackId);
    List<CloudVmMetaDataStatus> results = new ArrayList<>();
    List<Map<String, Object>> outputs = heatStack.getOutputs();
    for (Map<String, Object> map : outputs) {
        String instanceUUID = (String) map.get("output_value");
        if (!StringUtils.isEmpty(instanceUUID)) {
            Server server = client.compute().servers().get(instanceUUID);
            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;
}
Also used : Server(org.openstack4j.model.compute.Server) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Stack(org.openstack4j.model.heat.Stack) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 33 with CloudVmInstanceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.

the class OpenStackNativeInstanceConnector method check.

@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> statuses = new ArrayList<>();
    OSClient<?> osClient = openStackClient.createOSClient(ac);
    for (CloudInstance vm : vms) {
        Server server = osClient.compute().servers().get(vm.getInstanceId());
        if (server == null) {
            statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
        } else {
            statuses.add(new CloudVmInstanceStatus(vm, NovaInstanceStatus.get(server)));
        }
    }
    return statuses;
}
Also used : Server(org.openstack4j.model.compute.Server) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 34 with CloudVmInstanceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.

the class MockScalingTest method configMockServer.

@BeforeClass
@Parameters({ "mockPort", "sshPort", "desiredCount", "hostGroup" })
public void configMockServer(@Optional("9443") int mockPort, @Optional("2020") int sshPort, int desiredCount, String hostGroup) {
    IntegrationTestContext itContext = getItContext();
    String clusterName = itContext.getContextParam(CloudbreakV2Constants.STACK_NAME);
    StackResponse response = getCloudbreakClient().stackV2Endpoint().getPrivate(clusterName, null);
    java.util.Optional<InstanceGroupResponse> igg = response.getInstanceGroups().stream().filter(ig -> ig.getGroup().equals(hostGroup)).findFirst();
    Map<String, CloudVmInstanceStatus> instanceMap = itContext.getContextParam(CloudbreakITContextConstants.MOCK_INSTANCE_MAP, Map.class);
    ScalingMock scalingMock = (ScalingMock) applicationContext.getBean(ScalingMock.NAME, mockPort, sshPort, instanceMap);
    scalingMock.addSPIEndpoints();
    scalingMock.addMockEndpoints();
    scalingMock.addAmbariMappings(clusterName);
    itContext.putContextParam(CloudbreakV2Constants.MOCK_SERVER, scalingMock);
    igg.ifPresent(ig -> {
        int scalingAdjustment = desiredCount - ig.getNodeCount();
        if (scalingAdjustment > 0) {
            scalingMock.addInstance(scalingAdjustment);
        }
    });
}
Also used : AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Test(org.testng.annotations.Test) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakITContextConstants(com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants) Optional(org.testng.annotations.Optional) ScalingUtil(com.sequenceiq.it.cloudbreak.scaling.ScalingUtil) Assert(org.testng.Assert) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) StackV2Request(com.sequenceiq.cloudbreak.api.model.v2.StackV2Request) CloudbreakV2Constants(com.sequenceiq.it.cloudbreak.v2.CloudbreakV2Constants) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) StackScalingV2Test(com.sequenceiq.it.cloudbreak.v2.StackScalingV2Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) BeforeClass(org.testng.annotations.BeforeClass) Parameters(org.testng.annotations.Parameters)

Example 35 with CloudVmInstanceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.

the class MockServer method terminateInstance.

public static void terminateInstance(Map<String, CloudVmMetaDataStatus> instanceMap, String instanceId) {
    CloudVmMetaDataStatus vmMetaDataStatus = instanceMap.get(instanceId);
    InstanceTemplate oldTemplate = vmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance().getTemplate();
    InstanceTemplate newTemplate = new InstanceTemplate("medium", "group", oldTemplate.getPrivateId(), new ArrayList<>(), InstanceStatus.TERMINATED, null, 0L);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    CloudInstance cloudInstanceWithId = new CloudInstance(instanceId, newTemplate, instanceAuthentication);
    CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstanceWithId, InstanceStatus.TERMINATED);
    CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, vmMetaDataStatus.getMetaData());
    instanceMap.put(instanceId, cloudVmMetaDataStatus);
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)39 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)32 ArrayList (java.util.ArrayList)21 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)12 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)9 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)8 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)8 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)5 Server (org.openstack4j.model.compute.Server)5 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)4 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)4 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)4 List (java.util.List)4 Map (java.util.Map)4 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)3 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)3 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2