@Test(expected = InvalidClusterException.class) public void testRequestedLeaseTooBig() throws InvalidClusterException { LeaseDuration leaseDuration = LeaseDuration.of("5m", "0", "0"); leaseDuration.calcInitialLease("6m"); } }
@Override public JsonElement serialize(LeaseDuration leaseDuration, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("initial", context.serialize(leaseDuration.getInitial())); jsonObj.add("max", context.serialize(leaseDuration.getMax())); jsonObj.add("step", context.serialize(leaseDuration.getStep())); return jsonObj; } }
public LeaseDuration build() { return new LeaseDuration(initial, max, step); } }
/** * Calculate the initial lease to use given the initial lease here and a requested initial lease. The requested * lease must be equal to or less than the initial lease here. Takes into account that a lease of 0 is an infinite * lease. * * @param requestedInitialLease Requested initial lease. * @return The smaller of the leases. * @throws InvalidClusterException if the requested lease is larger than the allowed initial lease, or if it is * less than negative one. */ public long calcInitialLease(String requestedInitialLease) throws InvalidClusterException { return calcInitialLease(getTimestamp(requestedInitialLease)); }
@Test public void testLeaseDuration() { LeaseDuration leaseDuration = LeaseDuration.of("7d", "0", "0"); Assert.assertEquals(604800000, leaseDuration.getInitial()); Assert.assertEquals(0, leaseDuration.getStep()); leaseDuration = LeaseDuration.of("3s", "0", "0"); Assert.assertEquals(3000, leaseDuration.getInitial()); leaseDuration = LeaseDuration.of("5m", "0", "0"); Assert.assertEquals(300000, leaseDuration.getInitial()); leaseDuration = LeaseDuration.of("10h", "0", "0"); Assert.assertEquals(36000000, leaseDuration.getInitial()); leaseDuration = LeaseDuration.of("0", "0", "0"); Assert.assertEquals(0, leaseDuration.getInitial()); }
@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()); }
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; } }
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");
@Test(expected = RuntimeException.class) public void testUnsupportedArgStringConstructor() { LeaseDuration.of("1v", "0", "0"); }
long leaseDuration = template.getAdministration().getLeaseDuration().calcInitialLease(requestedLease); long createTime = System.currentTimeMillis(); builder.setCreateTime(createTime);
@Override public LeaseDuration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); LeaseDuration.Builder builder = LeaseDuration.builder(); builder.setInitial((String) context.deserialize(jsonObj.get("initial"), String.class)); builder.setMax((String) context.deserialize(jsonObj.get("max"), String.class)); builder.setStep((String) context.deserialize(jsonObj.get("step"), String.class)); return builder.build(); }
@Test(expected = RuntimeException.class) public void testInvalidArgStringConstructor() { LeaseDuration.of("invalidNumbers", "0", "0"); }
public static LeaseDuration of(long initial, long max, long step) { return builder().setInitial(initial).setMax(max).setStep(step).build(); }
@Test(expected = InvalidClusterException.class) public void testInvalidNegativeRequestedLease() throws InvalidClusterException { LeaseDuration leaseDuration = LeaseDuration.of("0", "0", "0"); leaseDuration.calcInitialLease(-2); }
@Test(expected = IllegalArgumentException.class) public void testNegativeArgStringConstructor() { LeaseDuration.of("-15s", "0", "0"); }
public static LeaseDuration of(String initial, String max, String step) { return builder().setInitial(initial).setMax(max).setStep(step).build(); }
@Test public void testCalcInitialLease() throws InvalidClusterException { LeaseDuration leaseDuration = LeaseDuration.of("15m", "0", "0"); Assert.assertEquals(2000, leaseDuration.calcInitialLease("2s")); }
@Test public void testLeaseDurationJsonAbsoluteTime() { LeaseDuration leaseDuration = LeaseDuration.of(123, 0, 1); Assert.assertEquals(leaseDuration, GSON.fromJson("{\"initial\":123,\"max\":0,\"step\":1}", LeaseDuration.class)); }
@Test public void testCalcInitialLeaseNegativeOne() throws InvalidClusterException { LeaseDuration leaseDuration = LeaseDuration.of("5m", "0", "0"); Assert.assertEquals(300000, leaseDuration.calcInitialLease(-1)); }
@Test public void testLeaseDurationJsonMissingMax() { LeaseDuration leaseDuration = LeaseDuration.of(123, 0, 1); Assert.assertEquals(leaseDuration, GSON.fromJson("{\"initial\":123,\"step\":1}", LeaseDuration.class)); }