@Override public V setDescription(String description) { this.description = description; return getThis(); }
/** * Get a builder for creating cluster defaults. * * @return Builder for creating cluster defaults. */ public static Builder builder() { return new Builder(); }
/** * Get a builder for creating cluster templates. * * @return Builder for creating cluster templates. */ public static ClusterTemplate.Builder builder() { return new Builder(); }
@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(); }
private ClusterTemplate copyWithNewCompatibilities(ClusterTemplate template, Compatibilities newCompatibilities) { return ClusterTemplate.builder() .setName(template.getName()) .setDescription(template.getDescription()) .setClusterDefaults(template.getClusterDefaults()) .setCompatibilities(newCompatibilities) .setConstraints(template.getConstraints()) .setAdministration(template.getAdministration()) .build(); }
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; } }
public static LeaseDuration of(long initial, long max, long step) { return builder().setInitial(initial).setMax(max).setStep(step).build(); }
private JsonObject getConfig(ClusterTemplate template, ClusterCreateRequest createRequest) { // use the config from the request if it exists. Otherwise use the template default JsonObject config = createRequest.getConfig(); if (config == null) { config = template.getClusterDefaults().getConfig(); } return config; }
/** * 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)); }
@Override protected AbstractTemplate.Builder getConcreteBuilder() { return ClusterTemplate.builder(); } }
/** * Get a builder for creating compatibilities. * * @return Builder for creating compatibilities. */ public static Builder builder() { return new Builder(); }
public Compatibilities build() { return new Compatibilities(hardwaretypes, imagetypes, services); } }
@Override public ClusterTemplate build() { return new ClusterTemplate(this, clusterDefaults, compatibilities, constraints, administration, links, parent, includes); }
@Override protected AbstractTemplate.Builder getConcreteBuilder() { return PartialTemplate.builder(); } }
/** * Get a builder for creating partial templates. * * @return Builder for creating partial templates. */ public static PartialTemplate.Builder builder() { return new Builder(); }
public static Builder builder() { return new Builder(); }
public static LeaseDuration of(String initial, String max, String step) { return builder().setInitial(initial).setMax(max).setStep(step).build(); }
@Override public V setName(String name) { this.name = name; return getThis(); }
@Override public V setIcon(String icon) { this.icon = icon; return getThis(); }
public V setConstraints(Constraints constraints) { this.constraints = constraints == null ? Constraints.EMPTY_CONSTRAINTS : constraints; return getThis(); }