@Override public Administration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); LeaseDuration leaseDuration = context.deserialize(jsonObj.get("leaseduration"), LeaseDuration.class); return new Administration(leaseDuration); }
@Override public JsonElement serialize(Administration administration, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("leaseduration", context.serialize(administration.getLeaseDuration())); return jsonObj; } }
private void copyFullProps(AbstractTemplate from, AbstractTemplate to, Set<String> immutables) throws TemplateImmutabilityException { copyMainProps(from, to, immutables, false); //merge constraints if(!from.constraints.equals(Constraints.EMPTY_CONSTRAINTS)) { Map<String, ServiceConstraint> serviceConstraint = mergeMap(to.constraints.serviceConstraints, from.constraints.serviceConstraints); Set<Set<String>> servicesThatMustCoexist = mergeSet(to.constraints.layoutConstraint.servicesThatMustCoexist, from.constraints.layoutConstraint.servicesThatMustCoexist); Set<Set<String>> servicesThatMustNotCoexist = mergeSet(to.constraints.layoutConstraint.servicesThatMustNotCoexist, from.constraints.layoutConstraint.servicesThatMustNotCoexist); to.constraints = new Constraints(serviceConstraint, new LayoutConstraint(servicesThatMustCoexist, servicesThatMustNotCoexist), from.constraints.sizeConstraint); } //merge admin lease duration if (!from.administration.equals(Administration.EMPTY_ADMINISTRATION)) { to.administration = from.administration; } }
private <T extends AbstractTemplate> boolean validateTemplate(T template, HttpResponder responder) { long initial = template.getAdministration().getLeaseDuration().getInitial(); initial = initial == 0 ? Long.MAX_VALUE : initial; long max = template.getAdministration().getLeaseDuration().getMax(); max = max == 0 ? Long.MAX_VALUE : max; if (max < initial) { responder.sendString(HttpResponseStatus.BAD_REQUEST, "Initial lease duration cannot be more than max lease duration for template " + template.getName()); return false; } return true; } }
@BeforeClass public static void initData() throws Exception { JsonObject defaultClusterConfig = new JsonObject(); defaultClusterConfig.addProperty("defaultconfig", "value1"); smallTemplate = ClusterTemplate.builder() .setName("one-machine") .setClusterDefaults( ClusterDefaults.builder() .setServices("zookeeper") .setProvider("rackspace") .setConfig(defaultClusterConfig) .build()) .setCompatibilities(Compatibilities.builder().setServices("zookeeper").build()) .setAdministration(new Administration(LeaseDuration.of("10s", "30s", "5s"))) .build(); }
long step = cluster.getClusterTemplate().getAdministration().getLeaseDuration().getStep(); step = step == 0 ? Long.MAX_VALUE : step; long clusterMaxDuration = cluster.getClusterTemplate().getAdministration().getLeaseDuration().getMax(); if (clusterMaxDuration != 0 && expireTime - cluster.getExpireTime() > step) { throw new IllegalArgumentException("New expire time cannot be greater than allowed increment");
.build()) .setCompatibilities(Compatibilities.builder().setServices("zookeeper").build()) .setAdministration(new Administration(LeaseDuration.of("10s", "30s", "5s"))) .build();
long leaseDuration = template.getAdministration().getLeaseDuration().calcInitialLease(requestedLease); long createTime = System.currentTimeMillis(); builder.setCreateTime(createTime);
.setProvider("rackspace") .build()) .setAdministration(new Administration(LeaseDuration.of("1s", "12s", "1s"))).build();
@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()); }