@Override public void writePartialTemplate(PartialTemplate partialTemplate) throws IOException, IllegalAccessException { int version = getVersion(EntityType.PARTIAL_TEMPLATE, partialTemplate.getName()); partialTemplate.setVersion(version); writeEntity(EntityType.PARTIAL_TEMPLATE, partialTemplate.getName(), version, serialize(partialTemplate, PartialTemplate.class)); partialTemplate.setVersion(Constants.DEFAULT_VERSION); }
@Override protected void addChildFields(PartialTemplate template, JsonObject jsonObj, JsonSerializationContext context) { super.addChildFields(template, jsonObj, context); jsonObj.add(IMMUTABLE_KEY, context.serialize(template.isImmutable())); }
public PartialTemplate build() { return new PartialTemplate(this, clusterDefaults, compatibilities, constraints, administration, links, immutable); }
view.deletePartialTemplate(partialTemplate.getName());
@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()); }
@Override protected AbstractTemplate.Builder getConcreteBuilder() { return PartialTemplate.builder(); } }
} else if (!partialTemplate.getName().equals(partialtemplateId)) { responder.sendString(HttpResponseStatus.BAD_REQUEST, "mismatch between partial template name and name in path."); return;
copyFullProps(fromTemplate, toTemplate, immutables); } else if (fromTemplate instanceof PartialTemplate) { Boolean isImmutable = ((PartialTemplate) fromTemplate).isImmutable(); copyMainProps(fromTemplate, toTemplate, immutables, isImmutable); } else {
@Test public void test_13_deleteTemplate() throws Exception { int beforePartialsCount = entityStoreView.getAllPartialTemplates().size(); int beforeClusterTemplatesCount = entityStoreView.getAllClusterTemplates().size(); entityStoreView.deleteClusterTemplate(insecureTemplate.getName()); entityStoreView.deletePartialTemplate(sensuPartial.getName()); int afterPartialsCount = entityStoreView.getAllPartialTemplates().size(); int afterClusterTemplatesCount = entityStoreView.getAllClusterTemplates().size(); Assert.assertEquals(afterPartialsCount, beforePartialsCount - 1); Assert.assertEquals(afterClusterTemplatesCount, beforeClusterTemplatesCount - 1); } }