/** * Get a builder for creating cluster create requests. * * @return Builder for creating cluster create requests. */ public static Builder builder() { return new Builder(); }
public ClusterCreateRequest build() { return new ClusterCreateRequest(name, description, clusterTemplateName, numMachines, providerName, providerFields, serviceNames, hardwareTypeName, imageTypeName, initialLeaseDuration, dnsSuffix, config); } }
@Override public int hashCode() { return Objects.hashCode(super.hashCode(), restart, config); } }
@Test(expected = MissingEntityException.class) public void testInvalidTemplateClusterCreate() throws Exception { String name = "clusty"; Map<String, Object> providerFields = ImmutableMap.<String, Object>of("keyname", "ec2", "key", "keycontents"); ClusterCreateRequest createRequest = ClusterCreateRequest.builder() .setName(name) .setClusterTemplateName("not" + basicTemplate.getName()) .setNumMachines(1) .setProviderFields(providerFields) .build(); clusterService.requestClusterCreate(createRequest, account); }
@Test(expected = IllegalArgumentException.class) public void testDisallowedServicesThrowsException() throws Exception { ClusterCreateRequest request = ClusterCreateRequest.builder() .setName("mycluster") .setClusterTemplateName(reactorTemplate.getName()) .setNumMachines(5) .setProviderName("joyent") .setServiceNames(ImmutableSet.of("namenode", "datanode", "mysql", "httpd")) .setInitialLeaseDuration(-1L) .build(); solver.solveClusterNodes( getBaseBuilder().setClusterTemplate(reactorTemplate).setProvider(Entities.ProviderExample.JOYENT).build(), request); }
@Override public TakeTaskRequest deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String workerId = context.deserialize(jsonObj.get("workerId"), String.class); String provisionerId = context.deserialize(jsonObj.get("provisionerId"), String.class); String tenantId = context.deserialize(jsonObj.get("tenantId"), String.class); return new TakeTaskRequest(workerId, provisionerId, tenantId); } }
@Override public TenantWriteRequest deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); TenantSpecification tenantSpec = context.deserialize(jsonObj.get("tenant"), TenantSpecification.class); Boolean bootstrap = context.deserialize(jsonObj.get("bootstrap"), Boolean.class); return new TenantWriteRequest(tenantSpec, bootstrap); } }
private Set<String> getServices(ClusterTemplate template, ClusterCreateRequest createRequest) { // set cluster service names. Dependency checking is done later on since it involves a lot of potential lookups. Set<String> serviceNames = createRequest.getServices(); if (serviceNames == null || serviceNames.isEmpty()) { serviceNames = template.getClusterDefaults().getServices(); } return serviceNames; }
@Test public void testFinishTaskForDeadProvisionerErrors() throws Exception { FinishTaskRequest finishRequest = new FinishTaskRequest("workerX", "nonexistant-provider", "tenantY", "taskId", "stdout", "stderr", 0, null, null, null); assertResponseStatus(doPostInternalAPI("/tasks/finish", gson.toJson(finishRequest)), HttpResponseStatus.FORBIDDEN); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ClusterConfigureRequest that = (ClusterConfigureRequest) o; return super.equals(that) && Objects.equal(restart, that.restart) && Objects.equal(config, that.config); }
private JsonObject getConfig(ClusterTemplate template, ClusterCreateRequest createRequest) { // use the config from the request if it exists. Otherwise use the template default JsonObject config = createRequest.getConfig(); if (config == null) { config = template.getClusterDefaults().getConfig(); } return config; }
@Test(expected = MissingEntityException.class) public void testInvalidProviderClusterCreate() throws Exception { String name = "clusty"; Map<String, Object> providerFields = ImmutableMap.<String, Object>of("keyname", "ec2", "key", "keycontents"); ClusterCreateRequest createRequest = ClusterCreateRequest.builder() .setName(name) .setClusterTemplateName(basicTemplate.getName()) .setProviderName("not" + provider.getName()) .setNumMachines(1) .setProviderFields(providerFields) .build(); clusterService.requestClusterCreate(createRequest, account); }
@Test(expected = IllegalArgumentException.class) public void testMissingServiceDependenciesThrowsException() throws Exception { ClusterCreateRequest request = ClusterCreateRequest.builder() .setName("mycluster") .setClusterTemplateName(reactorTemplate.getName()) .setNumMachines(5) .setProviderName("joyent") .setServiceNames(ImmutableSet.of("reactor", "datanode")) .setInitialLeaseDuration(-1L) .build(); solver.solveClusterNodes( getBaseBuilder().setClusterTemplate(reactorTemplate).setProvider(Entities.ProviderExample.JOYENT).build(), request); }
@Test public void testTakeTaskForDeadProvisionerErrors() throws Exception { TakeTaskRequest takeRequest = new TakeTaskRequest("workerX", "nonexistant-provider", "tenantY"); assertResponseStatus(doPostInternalAPI("/tasks/take", gson.toJson(takeRequest)), HttpResponseStatus.FORBIDDEN); }
@Override public int hashCode() { return Objects.hashCode(super.hashCode(), name, description, clusterTemplate, numMachines, provider, services, hardwaretype, imagetype, initialLeaseDuration, dnsSuffix, config); }
@Test public void testGetClusterNotOwnedByUserReturns404() throws Exception { ClusterCreateRequest clusterCreateRequest = ClusterCreateRequest.builder() .setName("cluster1") .setClusterTemplateName(reactorTemplate.getName()) .setNumMachines(5) .build(); HttpResponse response = doPostExternalAPI("/clusters", gson.toJson(clusterCreateRequest), USER1_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); String clusterId = getIdFromResponse(response); assertResponseStatus(doGetExternalAPI("/clusters/" + clusterId, USER2_HEADERS), HttpResponseStatus.NOT_FOUND); }
@Test(expected = IllegalArgumentException.class) public void testNoAvailableHardwareTypesThrowsException() throws Exception { ClusterCreateRequest request = ClusterCreateRequest.builder() .setName("mycluster") .setClusterTemplateName(reactorTemplate.getName()) .setNumMachines(5) .setProviderName("rackspace") .setServiceNames(ImmutableSet.of("namenode", "datanode")) .setInitialLeaseDuration(-1L) .build(); solver.solveClusterNodes( getBaseBuilder().setClusterTemplate(reactorTemplate).setProvider(Entities.ProviderExample.RACKSPACE).build(), request); }
@Test public void testAdminCanGetClustersOwnedByOthers() throws Exception { ClusterCreateRequest clusterCreateRequest = ClusterCreateRequest.builder() .setName("cluster1") .setClusterTemplateName(reactorTemplate.getName()) .setNumMachines(5) .build(); HttpResponse response = doPostExternalAPI("/clusters", gson.toJson(clusterCreateRequest), USER1_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); String clusterId = getIdFromResponse(response); assertResponseStatus(doGetExternalAPI("/clusters/" + clusterId, ADMIN_HEADERS), HttpResponseStatus.OK); }
@Test public void testMaxClusterSize() throws Exception { Configuration conf = Configuration.create(); int maxClusterSize = conf.getInt(Constants.MAX_CLUSTER_SIZE); ClusterCreateRequest clusterCreateRequest = ClusterCreateRequest.builder() .setName("cluster") .setClusterTemplateName(smallTemplate.getName()) .setNumMachines(maxClusterSize + 1) .build(); assertResponseStatus(doPostExternalAPI("/clusters", gson.toJson(clusterCreateRequest), USER1_HEADERS), HttpResponseStatus.BAD_REQUEST); }
@Test public void testDeleteOnClusterNotOwnedByUserReturns404() throws Exception { ClusterCreateRequest clusterCreateRequest = ClusterCreateRequest.builder() .setName("cluster1") .setClusterTemplateName(reactorTemplate.getName()) .setNumMachines(5) .build(); HttpResponse response = doPostExternalAPI("/clusters", gson.toJson(clusterCreateRequest), USER1_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); String clusterId = getIdFromResponse(response); assertResponseStatus(doDeleteExternalAPI("/clusters/" + clusterId, USER2_HEADERS), HttpResponseStatus.NOT_FOUND); }