Search in sources :

Example 36 with CloudVmMetaDataStatus

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

Example 37 with CloudVmMetaDataStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus 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);
    });
}
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 38 with CloudVmMetaDataStatus

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

the class ScalingMock method addAmbariMappings.

public void addAmbariMappings(String clusterName) {
    Service sparkService = getSparkService();
    Map<String, CloudVmMetaDataStatus> instanceMap = getInstanceMap();
    sparkService.get(AMBARI_API_ROOT + "/check", new AmbariCheckResponse());
    sparkService.get(AMBARI_API_ROOT + "/clusters/:cluster/requests/:request", new AmbariStatusResponse());
    sparkService.get(AMBARI_API_ROOT + "/clusters", new AmbariClusterResponse(instanceMap, clusterName));
    sparkService.post(AMBARI_API_ROOT + "/clusters/:cluster/requests", new AmbariClusterRequestsResponse());
    sparkService.post(AMBARI_API_ROOT + "/clusters/:cluster", new EmptyAmbariResponse());
    sparkService.get(AMBARI_API_ROOT + "/clusters/:cluster", new AmbariClusterResponse(instanceMap, clusterName));
    sparkService.get(AMBARI_API_ROOT + "/hosts", new AmbariHostsResponse(instanceMap), gson()::toJson);
    sparkService.get(AMBARI_API_ROOT + "/clusters/:cluster/hosts", new AmbariClustersHostsResponse(instanceMap, "INSTALLED"));
    sparkService.put(AMBARI_API_ROOT + "/clusters/:cluster/services/*", new AmbariClusterRequestsResponse());
    sparkService.post(AMBARI_API_ROOT + "/clusters/:cluster/hosts", new AmbariClusterRequestsResponse());
    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");
    });
    sparkService.get(AMBARI_API_ROOT + "/clusters/:clusterName/hosts/:internalhostname", (request, response) -> {
        response.type("text/plain");
        ObjectNode rootNode = JsonNodeFactory.instance.objectNode();
        rootNode.putObject("Hosts").put("public_host_name", request.params("internalhostname")).put("host_status", "HEALTHY");
        return rootNode;
    });
    sparkService.get(AMBARI_API_ROOT + "/clusters/:clusterName/services/HDFS/components/NAMENODE", (request, response) -> {
        response.type("text/plain");
        ObjectNode rootNode = JsonNodeFactory.instance.objectNode();
        ObjectNode nameNode = rootNode.putObject("metrics").putObject("dfs").putObject("namenode");
        ObjectNode liveNodesRoot = JsonNodeFactory.instance.objectNode();
        for (CloudVmMetaDataStatus status : instanceMap.values()) {
            ObjectNode node = liveNodesRoot.putObject(HostNameUtil.generateHostNameByIp(status.getMetaData().getPrivateIp()));
            node.put("remaining", "10000000");
            node.put("usedSpace", Integer.toString(100000));
            node.put("adminState", "In Service");
        }
        nameNode.put("LiveNodes", liveNodesRoot.toString());
        nameNode.put("DecomNodes", "{}");
        return rootNode;
    });
    sparkService.put(AMBARI_API_ROOT + "/clusters/:cluster/host_components", new AmbariClusterRequestsResponse());
    sparkService.delete(AMBARI_API_ROOT + "/clusters/:cluster/hosts/:hostname/host_components/*", new EmptyAmbariResponse());
    sparkService.delete(AMBARI_API_ROOT + "/clusters/:cluster/hosts/:hostname", new AmbariClusterRequestsResponse());
    sparkService.post(AMBARI_API_ROOT + "/users", new EmptyAmbariResponse());
}
Also used : AmbariComponentStatusOnHostResponse(com.sequenceiq.it.spark.ambari.AmbariComponentStatusOnHostResponse) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AmbariHostsResponse(com.sequenceiq.it.spark.ambari.AmbariHostsResponse) Service(spark.Service) AmbariClusterRequestsResponse(com.sequenceiq.it.spark.ambari.AmbariClusterRequestsResponse) AmbariStatusResponse(com.sequenceiq.it.spark.ambari.AmbariStatusResponse) EmptyAmbariResponse(com.sequenceiq.it.spark.ambari.EmptyAmbariResponse) AmbariClusterResponse(com.sequenceiq.it.spark.ambari.AmbariClusterResponse) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) AmbariClustersHostsResponse(com.sequenceiq.it.spark.ambari.AmbariClustersHostsResponse) AmbariServiceConfigResponse(com.sequenceiq.it.spark.ambari.AmbariServiceConfigResponse) AmbariCheckResponse(com.sequenceiq.it.spark.ambari.AmbariCheckResponse)

Example 39 with CloudVmMetaDataStatus

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

the class AmbariClustersHostsResponse method handle.

@Override
public Object handle(Request request, Response response) {
    response.type("text/plain");
    ObjectNode rootNode = JsonNodeFactory.instance.objectNode();
    ArrayNode items = rootNode.putArray("items");
    for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
        CloudVmMetaDataStatus status = stringCloudVmMetaDataStatusEntry.getValue();
        if (InstanceStatus.STARTED == status.getCloudVmInstanceStatus().getStatus()) {
            ObjectNode item = items.addObject();
            item.putObject("Hosts").put("host_name", HostNameUtil.generateHostNameByIp(status.getMetaData().getPrivateIp()));
            ArrayNode components = item.putArray("host_components");
            components.addObject().putObject("HostRoles").put("component_name", "DATANODE").put("state", state);
            components.addObject().putObject("HostRoles").put("component_name", "NODEMANAGER").put("state", state);
        }
    }
    return rootNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 40 with CloudVmMetaDataStatus

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

the class AwsMetaDataCollectorTest method collectMigratedExistingOneGroup.

@Test
public void collectMigratedExistingOneGroup() {
    List<CloudInstance> vms = new ArrayList<>();
    List<Volume> volumes = new ArrayList<>();
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    vms.add(new CloudInstance("i-1", new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
    when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);
    when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway"))).thenReturn("cbgateway-AAA");
    List<String> gatewayIds = Collections.singletonList("i-1");
    when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA"))).thenReturn(gatewayIds);
    when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);
    when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);
    Instance instance = Mockito.mock(Instance.class);
    when(instance.getInstanceId()).thenReturn("i-1");
    when(instance.getPrivateIpAddress()).thenReturn("privateIp");
    when(instance.getPublicIpAddress()).thenReturn("publicIp");
    List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance));
    when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);
    AuthenticatedContext ac = authenticatedContext();
    List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);
    verify(amazonEC2Client).createTags(any(CreateTagsRequest.class));
    Assert.assertEquals(1, statuses.size());
    Assert.assertEquals("i-1", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
    Assert.assertEquals("privateIp", statuses.get(0).getMetaData().getPrivateIp());
    Assert.assertEquals("publicIp", statuses.get(0).getMetaData().getPublicIp());
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) Reservation(com.amazonaws.services.ec2.model.Reservation) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.Test)

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