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);
}
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);
});
}
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());
}
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;
}
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());
}
Aggregations