public PolicyDescriptor(Policy policy) { this.id = policy.getId(); this.type = policy.getPolicyType().getName(); this.name = policy.getName(); } public String getId() {
protected PolicySpec(Class<T> type) { checkIsImplementation(type); checkIsNewStyleImplementation(type); this.type = type; }
/** * Creates a new {@link EnricherSpec} instance for an enricher of the given type. The returned * {@link EnricherSpec} can then be customized. * * @param type A {@link Enricher} class */ public static <T extends Enricher> EnricherSpec<T> create(Class<T> type) { return new EnricherSpec<T>(type); }
@Override public String get(String application, String entityToken, String policyToken, String configKeyName) { Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); ConfigKey<?> ck = policy.getPolicyType().getConfigKey(configKeyName); if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); return getStringValueForDisplay(brooklyn(), policy, policy.getConfig(ck)); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Response set( String application, String entityToken, String policyToken, String configKeyName, String value ) { Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); ConfigKey<?> ck = policy.getPolicyType().getConfigKey(configKeyName); if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); policy.setConfig((ConfigKey)ck, TypeCoercions.coerce(value, ck.getType())); return Response.status(Response.Status.OK).build(); }
public static void dumpInfo(Policy pol, Writer out, String currentIndentation, String tab) throws IOException { out.append(currentIndentation+pol.toString()+"\n"); for (ConfigKey<?> key : sortConfigKeys(pol.getPolicyType().getConfigKeys())) { Object val = ((AbstractPolicy)pol).getConfigMap().getRawConfig(key); if (!isTrivial(val)) { out.append(currentIndentation+tab+tab+key); out.append(" = "); if (isSecret(key.getName())) out.append("xxxxxxxx"); else out.append(""+val); out.append("\n"); } } out.flush(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof PolicyType)) return false; PolicyType o = (PolicyType) obj; return Objects.equal(getName(), o.getName()) && Objects.equal(getConfigKeys(), o.getConfigKeys()); }
public static Lifecycle getPolicyStatus(Policy p) { if (p.isRunning()) return Lifecycle.RUNNING; if (p.isDestroyed()) return Lifecycle.DESTROYED; if (p.isSuspended()) return Lifecycle.STOPPED; // TODO could policy be in an error state? return Lifecycle.CREATED; }
@Override public List<PolicyConfigSummary> list( final String application, final String entityToken, final String policyToken ) { EntityLocal entity = brooklyn().getEntity(application, entityToken); Policy policy = brooklyn().getPolicy(entity, policyToken); List<PolicyConfigSummary> result = Lists.newArrayList(); for (ConfigKey<?> key : policy.getPolicyType().getConfigKeys()) { result.add(PolicyTransformer.policyConfigSummary(brooklyn(), entity, policy, key)); } return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof PolicyType)) return false; PolicyType o = (PolicyType) obj; return Objects.equal(name, o.getName()) && Objects.equal(getConfigKeys(), o.getConfigKeys()); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof EnricherType)) return false; EnricherType o = (EnricherType) obj; return Objects.equal(getName(), o.getName()) && Objects.equal(getConfigKeys(), o.getConfigKeys()); }
@Override public void stop() { setAttribute(SERVICE_STATE, Lifecycle.STOPPING); try { setAttribute(SERVICE_UP, calculateServiceUp()); for (Policy it : getPolicies()) { it.suspend(); } resize(0); setAttribute(SERVICE_STATE, Lifecycle.STOPPED); setAttribute(SERVICE_UP, calculateServiceUp()); } catch (Exception e) { setAttribute(SERVICE_STATE, Lifecycle.ON_FIRE); throw Exceptions.propagate(e); } }
/** * Creates a new {@link PolicySpec} instance with the given config, for a policy of the given type. * * This is primarily for groovy code; equivalent to {@code PolicySpec.create(type).configure(config)}. * * @param config The spec's configuration (see {@link PolicySpec#configure(Map)}). * @param type A {@link Policy} class */ public static <T extends Policy> PolicySpec<T> create(Map<?,?> config, Class<T> type) { return PolicySpec.create(type).configure(config); }
protected EnricherSpec(Class<T> type) { checkIsImplementation(type); checkIsNewStyleImplementation(type); this.type = type; }
/** * Creates a new {@link EnricherSpec} instance with the given config, for an enricher of the given type. * * This is primarily for groovy code; equivalent to {@code EnricherSpec.create(type).configure(config)}. * * @param config The spec's configuration (see {@link EnricherSpec#configure(Map)}). * @param type An {@link Enricher} class */ public static <T extends Enricher> EnricherSpec<T> create(Map<?,?> config, Class<T> type) { return EnricherSpec.create(type).configure(config); }
/** * Creates a new {@link PolicySpec} instance for a policy of the given type. The returned * {@link PolicySpec} can then be customized. * * @param type A {@link Policy} class */ public static <T extends Policy> PolicySpec<T> create(Class<T> type) { return new PolicySpec<T>(type); }
public <V> PolicySpec<T> configureIfNotNull(ConfigKey<V> key, V val) { return (val != null) ? configure(key, val) : this; }
public <V> EnricherSpec<T> configureIfNotNull(ConfigKey<V> key, V val) { return (val != null) ? configure(key, val) : this; }
private <T extends Policy> T construct(Class<? extends T> clazz, PolicySpec<T> spec) throws InstantiationException, IllegalAccessException, InvocationTargetException { if (isNewStylePolicy(clazz)) { return clazz.newInstance(); } else { return constructOldStyle(clazz, MutableMap.copyOf(spec.getFlags())); } }
private <T extends Enricher> T construct(Class<? extends T> clazz, EnricherSpec<T> spec) throws InstantiationException, IllegalAccessException, InvocationTargetException { if (isNewStyleEnricher(clazz)) { return clazz.newInstance(); } else { return constructOldStyle(clazz, MutableMap.copyOf(spec.getFlags())); } }