Search in sources :

Example 31 with CloudVmMetaDataStatus

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

the class MockInstanceUtil method addInstance.

public void addInstance(Map<String, CloudVmMetaDataStatus> instanceMap, 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);
    });
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ServerAddressGenerator(com.sequenceiq.it.util.ServerAddressGenerator) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 32 with CloudVmMetaDataStatus

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

the class MockInstanceUtil method terminateInstance.

public 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)

Example 33 with CloudVmMetaDataStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus 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 34 with CloudVmMetaDataStatus

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

the class InstanceTerminationMock method addAmbariMappings.

public void addAmbariMappings(String clusterName) {
    Map<String, CloudVmMetaDataStatus> instanceMap = getInstanceMap();
    Service sparkService = getSparkService();
    int requestId = 100;
    sparkService.delete(AMBARI_API_ROOT + "/clusters/:cluster/hosts/:hostname", new EmptyAmbariResponse());
    sparkService.delete(AMBARI_API_ROOT + "/clusters/:cluster/hosts/:hostname/host_components/*", new EmptyAmbariResponse());
    sparkService.get(AMBARI_API_ROOT + "/clusters/:cluster/hosts/:hostname/host_components/*", new AmbariComponentStatusOnHostResponse());
    sparkService.post(AMBARI_API_ROOT + "/clusters/" + clusterName + "/requests", new AmbariRequestIdRespone(requestId));
    sparkService.get(AMBARI_API_ROOT + "/clusters/" + clusterName + "/requests/100", new AmbariRequestStatusResponse(requestId, 100));
    sparkService.put(AMBARI_API_ROOT + "/clusters/" + clusterName + "/requests/" + requestId, new EmptyAmbariClusterResponse());
    sparkService.put(AMBARI_API_ROOT + "/clusters/" + clusterName + "/host_components", new AmbariStrRequestIdRespone(requestId));
    sparkService.get(AMBARI_API_ROOT + "/clusters/:cluster/hosts", new AmbariHostComponentStateResponse(instanceMap));
    sparkService.get(AMBARI_API_ROOT + "/clusters/:cluster/hosts/:hostname", new AmbariHostResponse());
    sparkService.get(AMBARI_API_ROOT + "/clusters", new AmbariClusterResponse(instanceMap, clusterName));
    sparkService.get(AMBARI_API_ROOT + "/clusters/" + clusterName, new AmbariClustersHostsResponse(instanceMap, "SUCCESSFUL"));
    sparkService.post(AMBARI_API_ROOT + "/clusters/" + clusterName, new EmptyAmbariClusterResponse());
    sparkService.get(AMBARI_API_ROOT + "/clusters/:cluster/hosts/:hostname/host_components", new AmbariComponentStatusOnHostResponse());
    sparkService.get(AMBARI_API_ROOT + "/clusters/" + clusterName + "/configurations/service_config_versions", new AmbariServiceConfigResponse(getMockServerAddress(), getMockPort()), gson()::toJson);
    sparkService.get(AMBARI_API_ROOT + "/blueprints/:blueprintname", (request, response) -> {
        response.type("text/plain");
        return responseFromJsonFile("blueprint/" + request.params("blueprintname") + ".bp");
    });
}
Also used : AmbariHostResponse(com.sequenceiq.it.spark.ambari.v2.AmbariHostResponse) AmbariComponentStatusOnHostResponse(com.sequenceiq.it.spark.ambari.AmbariComponentStatusOnHostResponse) EmptyAmbariClusterResponse(com.sequenceiq.it.spark.ambari.EmptyAmbariClusterResponse) Service(spark.Service) AmbariRequestStatusResponse(com.sequenceiq.it.spark.ambari.v2.AmbariRequestStatusResponse) AmbariStrRequestIdRespone(com.sequenceiq.it.spark.ambari.v2.AmbariStrRequestIdRespone) AmbariRequestIdRespone(com.sequenceiq.it.spark.ambari.v2.AmbariRequestIdRespone) EmptyAmbariResponse(com.sequenceiq.it.spark.ambari.EmptyAmbariResponse) EmptyAmbariClusterResponse(com.sequenceiq.it.spark.ambari.EmptyAmbariClusterResponse) AmbariClusterResponse(com.sequenceiq.it.spark.ambari.AmbariClusterResponse) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) AmbariClustersHostsResponse(com.sequenceiq.it.spark.ambari.v2.AmbariClustersHostsResponse) AmbariServiceConfigResponse(com.sequenceiq.it.spark.ambari.AmbariServiceConfigResponse) AmbariHostComponentStateResponse(com.sequenceiq.it.spark.ambari.v2.AmbariHostComponentStateResponse)

Example 35 with CloudVmMetaDataStatus

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

the class MockSparkServer method addSaltMappings.

private static void addSaltMappings(Map<String, CloudVmMetaDataStatus> instanceMap) {
    ObjectMapper objectMapper = new ObjectMapper();
    get(SALT_BOOT_ROOT + "/health", (request, response) -> {
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        return genericResponse;
    }, GSON::toJson);
    objectMapper.setVisibility(objectMapper.getVisibilityChecker().withGetterVisibility(Visibility.NONE));
    post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(instanceMap));
    post(SALT_BOOT_ROOT + "/file", (request, response) -> {
        response.status(HttpStatus.CREATED.value());
        return response;
    });
    post(SALT_BOOT_ROOT + "/salt/server/pillar", (request, response) -> {
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        return genericResponse;
    }, GSON::toJson);
    post(SALT_BOOT_ROOT + "/salt/action/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        genericResponses.setResponses(new ArrayList<>());
        return genericResponses;
    }, GSON::toJson);
    post(SALT_BOOT_ROOT + "/hostname/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        List<GenericResponse> responses = new ArrayList<>();
        for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
            CloudVmMetaDataStatus cloudVmMetaDataStatus = stringCloudVmMetaDataStatusEntry.getValue();
            GenericResponse genericResponse = new GenericResponse();
            genericResponse.setAddress(cloudVmMetaDataStatus.getMetaData().getPrivateIp());
            genericResponse.setStatus(HostNameUtil.generateHostNameByIp(cloudVmMetaDataStatus.getMetaData().getPrivateIp()));
            genericResponse.setStatusCode(HttpStatus.OK.value());
            responses.add(genericResponse);
        }
        genericResponses.setResponses(responses);
        return genericResponses;
    }, GSON::toJson);
    post(SALT_BOOT_ROOT + "/file/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.CREATED.value());
        genericResponses.setResponses(Collections.singletonList(genericResponse));
        return genericResponses;
    }, GSON::toJson);
    post(SALT_BOOT_ROOT + "/salt/server/pillar/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        genericResponses.setResponses(Collections.singletonList(genericResponse));
        return genericResponses;
    }, GSON::toJson);
}
Also used : SaltApiRunPostResponse(com.sequenceiq.it.spark.salt.SaltApiRunPostResponse) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) ArrayList(java.util.ArrayList) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)43 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)20 ArrayList (java.util.ArrayList)18 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)13 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)12 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)10 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)9 Service (spark.Service)8 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Map (java.util.Map)7 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)6 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)6 Instance (com.amazonaws.services.ec2.model.Instance)6 Reservation (com.amazonaws.services.ec2.model.Reservation)6 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 AmbariClusterResponse (com.sequenceiq.it.spark.ambari.AmbariClusterResponse)6 EmptyAmbariResponse (com.sequenceiq.it.spark.ambari.EmptyAmbariResponse)6 CreateTagsRequest (com.amazonaws.services.ec2.model.CreateTagsRequest)5 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)5