private void validateFields(AbstractTemplate to) { Preconditions.checkArgument(to.clusterDefaults.getServices() != null && !to.clusterDefaults.getServices().isEmpty(), "default services must be specified"); Preconditions.checkArgument(to.clusterDefaults.getProvider() != null, "default provider must be specified"); Preconditions.checkArgument(to.clusterDefaults.getDnsSuffix() == null || StringUtils.isValidDNSSuffix(to.clusterDefaults.getDnsSuffix()), to.clusterDefaults.getDnsSuffix() + " is an invalid DNS suffix."); }
@Override public JsonElement serialize(ClusterDefaults clusterDefaults, Type type, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add(SERVICES_KEY, context.serialize(clusterDefaults.getServices())); jsonObj.add(PROVIDER_KEY, context.serialize(clusterDefaults.getProvider())); jsonObj.add(HARDWARE_TYPE_KEY, context.serialize(clusterDefaults.getHardwaretype())); jsonObj.add(IMAGE_TYPE_KEY, context.serialize(clusterDefaults.getImagetype())); jsonObj.add(DNS_SUFFIX_KEY, context.serialize(clusterDefaults.getDnsSuffix())); jsonObj.add(CONFIG_KEY, context.serialize(clusterDefaults.getConfig())); return jsonObj; }
private Provider getProvider(ClusterTemplate template, ClusterCreateRequest request, EntityStoreView entityStore) throws IOException, MissingEntityException { // make sure the provider exists String providerName = request.getProvider(); if (providerName == null || providerName.isEmpty()) { providerName = template.getClusterDefaults().getProvider(); } Provider provider = entityStore.getProvider(providerName); if (provider == null) { throw new MissingEntityException("provider " + providerName + " does not exist."); } return provider; }
@Test public void testInvalidNumMachines() throws Exception { // when its below the min ClusterCreateRequest clusterCreateRequest =ClusterCreateRequest.builder() .setName("my-cluster") .setClusterTemplateName(reactorTemplate.getName()) .setProviderName(reactorTemplate.getClusterDefaults().getProvider()) .setNumMachines(1) .build(); assertResponseStatus(doPostExternalAPI("/clusters", gson.toJson(clusterCreateRequest), USER1_HEADERS), HttpResponseStatus.BAD_REQUEST); // when its above the max clusterCreateRequest = ClusterCreateRequest.builder() .setName("my-cluster") .setClusterTemplateName(reactorTemplate.getName()) .setProviderName(reactorTemplate.getClusterDefaults().getProvider()) .setNumMachines(500) .build(); assertResponseStatus(doPostExternalAPI("/clusters", gson.toJson(clusterCreateRequest), USER1_HEADERS), HttpResponseStatus.BAD_REQUEST); }
@Test public void test_06_resolveTemplateTest() throws Exception { ClusterTemplate rt = clusterService.resolveTemplate(account, secureTemplate); Assert.assertEquals(secureTemplate.getIncludes(), rt.getIncludes()); Assert.assertEquals(secureTemplate.getParent(), rt.getParent()); Assert.assertEquals(secureTemplate.getName(), rt.getName()); Assert.assertEquals(secureTemplate.getDescription(), rt.getDescription()); Assert.assertEquals(defaultsServices, rt.getClusterDefaults().getServices()); Assert.assertEquals(16, rt.getClusterDefaults().getConfig().entrySet().size()); Assert.assertEquals("rackspace", rt.getClusterDefaults().getProvider()); Assert.assertEquals("standard-large", rt.getClusterDefaults().getHardwaretype()); Assert.assertEquals("centos6", rt.getClusterDefaults().getImagetype()); Assert.assertEquals("example.com", rt.getClusterDefaults().getDnsSuffix()); Assert.assertEquals(2, rt.getConstraints().getLayoutConstraint().getServicesThatMustCoexist().size()); Assert.assertEquals(2, rt.getConstraints().getLayoutConstraint().getServicesThatMustNotCoexist().size()); Assert.assertEquals(serviceConstraints, rt.getConstraints().getServiceConstraints()); Assert.assertEquals(43200000, rt.getAdministration().getLeaseDuration().getInitial()); Assert.assertEquals(43200000, rt.getAdministration().getLeaseDuration().getStep()); Assert.assertEquals(compatibilitiesHardwaretypes, rt.getCompatibilities().getHardwaretypes()); Assert.assertEquals(compatibilitiesImagetypes, rt.getCompatibilities().getImagetypes()); Assert.assertEquals(compatibilitiesServices, rt.getCompatibilities().getServices()); //overrides in child Assert.assertEquals("ldap.correct.com", rt.getClusterDefaults().getConfig().get("ldap") .getAsJsonObject().get("endpoint").getAsString()); Assert.assertNull(rt.getLabel()); Assert.assertNull(rt.getIcon()); Assert.assertEquals("cdap-distributed-secure-hadoop", rt.getName()); Assert.assertEquals("Cask DAP (CDAP) with Security and Secure Hadoop cluster with single master", rt.getDescription()); }