private void validateServicesToAdd(Cluster cluster, Set<String> servicesToAdd, Map<String, Service> serviceMap) { validateServiceCompatibilities(cluster.getClusterTemplate().getCompatibilities(), servicesToAdd); validateServiceDependencies(serviceMap); }
private Map<String, Map<String, String>> getImageTypeMap(String providerName, ClusterTemplate template, String requiredImageType, EntityStoreView entityStore) throws Exception { Map<String, Map<String, String>> imageMap = Maps.newHashMap(); Compatibilities compatibilities = template.getCompatibilities(); if (requiredImageType != null) { addProviderImage(imageMap, providerName, compatibilities, entityStore.getImageType(requiredImageType)); return imageMap; } for (ImageType imageType : entityStore.getAllImageTypes()) { addProviderImage(imageMap, providerName, compatibilities, imageType); } return imageMap; }
private Map<String, String> getHardwareTypeMap(String providerName, ClusterTemplate template, String requiredHardwareType, EntityStoreView entityStore) throws Exception { Map<String, String> flavorMap = Maps.newHashMap(); Compatibilities compatibilities = template.getCompatibilities(); if (requiredHardwareType != null) { addProviderFlavor(flavorMap, providerName, compatibilities, entityStore.getHardwareType(requiredHardwareType)); return flavorMap; } for (HardwareType hardwareType : entityStore.getAllHardwareTypes()) { addProviderFlavor(flavorMap, providerName, compatibilities, hardwareType); } return flavorMap; }
public boolean isCompatibleWithTemplate(ClusterTemplate template) { // check all services are compatible Compatibilities compatibilities = template.getCompatibilities(); if (!compatibilities.compatibleWithServices(serviceCounts.elementSet())) { return false; } // check all image types and hardware types are compatible Set<String> imageTypes = Sets.newHashSet(); Set<String> hardwareTypes = Sets.newHashSet(); for (NodeLayout nodeLayout : layout.elementSet()) { imageTypes.add(nodeLayout.getImageTypeName()); hardwareTypes.add(nodeLayout.getHardwareTypeName()); } // check all hardware types are compatible if (!compatibilities.compatibleWithImageTypes(imageTypes) || !compatibilities.compatibleWithHardwareTypes(hardwareTypes)) { return false; } return satisfiesConstraints(template.getConstraints()); }
/** * Add services to a cluster, returning which nodes were affected by the change or null if there was no way to * add the services to the cluster. * * @param cluster Cluster to add the services to. * @param clusterNodes Nodes in the cluster. * @param servicesToAdd Services to add to the cluster. * @return Nodes that need to have services added to them. * @throws Exception */ public Set<Node> addServicesToCluster(Cluster cluster, Set<Node> clusterNodes, Set<String> servicesToAdd) throws Exception { EntityStoreView entityStore = entityStoreService.getView(cluster.getAccount()); Map<String, Service> serviceMap = getServiceMap(Sets.union(cluster.getServices(), servicesToAdd), entityStore); validateServiceCompatibilities(cluster.getClusterTemplate().getCompatibilities(), servicesToAdd); validateServiceDependencies(serviceMap); ClusterLayoutTracker tracker = updater.addServicesToCluster(cluster, clusterNodes, servicesToAdd); if (tracker == null) { return null; } Set<Node> changedNodes = Sets.newHashSet(); for (ClusterLayoutChange change : tracker.getChanges()) { changedNodes.addAll(change.applyChange(cluster, clusterNodes, serviceMap)); } return changedNodes; }
serviceNames = template.getClusterDefaults().getServices(); validateServiceCompatibilities(template.getCompatibilities(), serviceNames);
.setHardwaretypes(template.getCompatibilities().getHardwaretypes()) .setImagetypes(template.getCompatibilities().getImagetypes()) .setServices("namenode", "datanode", "zookeeper") .build(); .setImagetypes(template.getCompatibilities().getImagetypes()) .setServices(template.getCompatibilities().getServices()) .build(); template = copyWithNewCompatibilities(template, newCompatibilities); .setHardwaretypes(template.getCompatibilities().getHardwaretypes()) .setImagetypes("ubuntu12") .setServices(template.getCompatibilities().getServices()) .build(); template = copyWithNewCompatibilities(template, newCompatibilities);
@Test public void test_03_persistentTemplatesConsistence() throws Exception { PartialTemplate ldapInternal = entityStoreView.getPartialTemplate("LDAP-internal"); PartialTemplate sensuInternal = entityStoreView.getPartialTemplate("sensu-internal"); ClusterTemplate cdapDistributedSecureHadoop = entityStoreView.getClusterTemplate("cdap-distributed-secure-hadoop"); ClusterTemplate cdapDistributedInsecure = entityStoreView.getClusterTemplate("cdap-distributed-insecure"); ClusterTemplate cdapDistributed = entityStoreView.getClusterTemplate("cdap-distributed"); Assert.assertNotNull(ldapInternal); Assert.assertNotNull(sensuInternal); Assert.assertNotNull(cdapDistributedSecureHadoop); Assert.assertNotNull(cdapDistributedInsecure); Assert.assertNotNull(cdapDistributed); Assert.assertEquals("Configure Example, Inc. LDAP services", ldapInternal.getDescription()); Assert.assertEquals(true, sensuInternal.isImmutable()); Assert.assertEquals("ldap-internal", ldapInternal.clusterDefaults.getServices().iterator().next()); Assert.assertEquals("ldap-internal", ldapInternal.compatibilities.getServices().iterator().next()); Assert.assertNotNull(ldapInternal.clusterDefaults.getConfig().get("ldap")); Assert.assertEquals("ldap.wrong.com", ldapInternal.clusterDefaults.getConfig().get("ldap") .getAsJsonObject().get("endpoint").getAsString()); Assert.assertEquals("Cask DAP (CDAP) with Security and Secure Hadoop cluster with single master", cdapDistributedSecureHadoop.getDescription()); Assert.assertNotNull(cdapDistributedSecureHadoop.getParent()); Assert.assertEquals("cdap-distributed", cdapDistributedSecureHadoop.getParent().getName()); Assert.assertNotNull(cdapDistributedSecureHadoop.getIncludes()); Assert.assertEquals("LDAP-internal", cdapDistributedSecureHadoop.getIncludes().iterator().next().getName()); Assert.assertEquals(3, cdapDistributedSecureHadoop.clusterDefaults.getServices().size()); Assert.assertNotNull(cdapDistributedSecureHadoop.getClusterDefaults().getConfig().get("hive")); Assert.assertEquals("kerberos-client", cdapDistributedSecureHadoop.getCompatibilities().getServices().iterator().next()); }
@Test public void test_07_not_persisted_resolveTemplate() throws Exception { InputStream notPersistedIn = classLoader.getResourceAsStream("partials/cdap-not-persisted.json"); ClusterTemplate notPersisted = gson.fromJson(IOUtils.toString(notPersistedIn), ClusterTemplate.class); ClusterTemplate rt = clusterService.resolveTemplate(account, notPersisted); Assert.assertEquals(notPersisted.getIncludes(), rt.getIncludes()); Assert.assertEquals(notPersisted.getParent(), rt.getParent()); Assert.assertEquals(notPersisted.getName(), rt.getName()); Assert.assertEquals(notPersisted.getDescription(), rt.getDescription()); Assert.assertEquals(sensuPartial.getClusterDefaults().getServices(), rt.getClusterDefaults().getServices()); Assert.assertEquals(sensuPartial.getClusterDefaults().getConfig(), rt.getClusterDefaults().getConfig()); Assert.assertEquals(sensuPartial.getCompatibilities().getServices(), rt.getCompatibilities().getServices()); }
@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()); }
Set<String> newCompatibleServices = Sets.newHashSet(template.getCompatibilities().getServices()); newCompatibleServices.add("new-service"); Compatibilities newCompatibilities = Compatibilities.builder() .setHardwaretypes(template.getCompatibilities().getHardwaretypes()) .setImagetypes(template.getCompatibilities().getImagetypes()) .setServices(newCompatibleServices).build(); ClusterTemplate updatedTemplate = ClusterTemplate.builder()
Compatibilities newCompatibilities = Compatibilities.builder() .setHardwaretypes(template.getCompatibilities().getHardwaretypes()) .setImagetypes(newCompatibleImages) .setServices(template.getCompatibilities().getServices()) .build(); ClusterTemplate updatedTemplate = ClusterTemplate.builder()