Java Code Examples for org.apache.brooklyn.api.effector.Effector#getName()

The following examples show how to use org.apache.brooklyn.api.effector.Effector#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EffectorTransformer.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static EffectorSummary effectorSummary(final Entity entity, Effector<?> effector, UriBuilder ub) {
    URI applicationUri = serviceUriBuilder(ub, ApplicationApi.class, "get").build(entity.getApplicationId());
    URI entityUri = serviceUriBuilder(ub, EntityApi.class, "get").build(entity.getApplicationId(), entity.getId());
    URI selfUri = serviceUriBuilder(ub, EffectorApi.class, "invoke").build(entity.getApplicationId(), entity.getId(), effector.getName());
    return new EffectorSummary(effector.getName(), effector.getReturnTypeName(),
             ImmutableSet.copyOf(Iterables.transform(effector.getParameters(),
            new Function<ParameterType<?>, EffectorSummary.ParameterSummary<?>>() {
                @Override
                public EffectorSummary.ParameterSummary<?> apply(@Nullable ParameterType<?> parameterType) {
                    return parameterSummary(entity, parameterType);
                }
            })), effector.getDescription(), ImmutableMap.of(
            "self", selfUri,
            "entity", entityUri,
            "application", applicationUri
    ));
}
 
Example 2
Source File: EffectorUtils.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes a method effector so that its progress is tracked. For internal use only, when we know the effector is backed by a method which is local.
 */
public static <T> T invokeMethodEffector(Entity entity, Effector<T> eff, Map<String,?> args) {
    Object[] parametersArray = EffectorUtils.prepareArgsForEffector(eff, args);
    String name = eff.getName();

    try {
        if (log.isDebugEnabled()) log.debug("Invoking effector {} on {}", new Object[] {name, entity});
        if (log.isTraceEnabled()) log.trace("Invoking effector {} on {} with args {}", new Object[] {name, entity, Sanitizer.sanitize(args)});
        EntityManagementSupport mgmtSupport = ((EntityInternal)entity).getManagementSupport();
        if (!mgmtSupport.isDeployed()) {
            mgmtSupport.attemptLegacyAutodeployment(name);
        }
        ManagementContextInternal mgmtContext = (ManagementContextInternal) ((EntityInternal) entity).getManagementContext();

        mgmtSupport.getEntityChangeListener().onEffectorStarting(eff, parametersArray);
        try {
            return mgmtContext.invokeEffectorMethodSync(entity, eff, args);
        } finally {
            mgmtSupport.getEntityChangeListener().onEffectorCompleted(eff);
        }
    } catch (Exception e) {
        throw handleEffectorException(entity, eff, e);
    }
}
 
Example 3
Source File: EffectorUtils.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static <T> Task<T> invokeEffectorAsync(Entity entity, Effector<T> eff, Map<String,?> parameters) {
    String name = eff.getName();

    if (log.isDebugEnabled()) log.debug("Invoking-async effector {} on {}", new Object[] { name, entity });
    if (log.isTraceEnabled()) log.trace("Invoking-async effector {} on {} with args {}", new Object[] { name, entity, Sanitizer.sanitize(parameters) });
    EntityManagementSupport mgmtSupport = ((EntityInternal)entity).getManagementSupport();
    if (!mgmtSupport.isDeployed()) {
        mgmtSupport.attemptLegacyAutodeployment(name);
    }
    ManagementContextInternal mgmtContext = (ManagementContextInternal) ((EntityInternal)entity).getManagementContext();

    // FIXME seems brittle to have the listeners in the Utils method; better to move into the context.invokeEff
    // (or whatever the last mile before invoking the effector is - though currently there is not such a canonical place!)
    mgmtSupport.getEntityChangeListener().onEffectorStarting(eff, parameters);
    try {
        return mgmtContext.invokeEffector(entity, eff, parameters);
    } finally {
        // FIXME this is really Effector submitted
        mgmtSupport.getEntityChangeListener().onEffectorCompleted(eff);
    }
}
 
Example 4
Source File: EffectorTransformer.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static EffectorSummary effectorSummaryForCatalog(Effector<?> effector) {
    Set<EffectorSummary.ParameterSummary<?>> parameters = ImmutableSet.copyOf(Iterables.transform(effector.getParameters(),
            new Function<ParameterType<?>, EffectorSummary.ParameterSummary<?>>() {
                @Override
                public EffectorSummary.ParameterSummary<?> apply(ParameterType<?> parameterType) {
                    return parameterSummary(null, parameterType);
                }
            }));
    return new EffectorSummary(effector.getName(),
            effector.getReturnTypeName(), parameters, effector.getDescription(), null);
}
 
Example 5
Source File: DynamicClusterImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * Creates tasks that obtain permits from {@link #childTaskSemaphore} before invoking <code>effector</code>
 * on <code>target</code>. Permits are released in a {@link ListenableFuture#addListener listener}. No
 * permits are obtained if {@link #childTaskSemaphore} is <code>null</code>.
 * @param target Entity to invoke effector on
 * @param effector Effector to invoke on target
 * @param arguments Effector arguments
 * @param isPrivileged If true the method obtains a permit from {@link #childTaskSemaphore}
 *                     immediately and returns the effector invocation task, otherwise it
 *                     returns a task that sequentially obtains a permit then runs the effector.
 * @return An unsubmitted task.
 */
protected <T> Task<?> newThrottledEffectorTask(Entity target, Effector<T> effector, Map<?, ?> arguments, boolean isPrivileged) {
    final Task<?> toSubmit;
    final Task<T> effectorTask = Effectors.invocation(target, effector, arguments).asTask();
    if (getChildTaskSemaphore() != null) {
        // permitObtained communicates to the release task whether the permit should really be released
        // or not. ObtainPermit sets it to true when a permit is acquired.
        final AtomicBoolean permitObtained = new AtomicBoolean();
        final String description = "Waiting for permit to run " + effector.getName() + " on " + target;
        final Runnable obtain = new ObtainPermit(getChildTaskSemaphore(), description, permitObtained);
        // Acquire the permit now for the privileged task and just queue the effector invocation.
        // If it's unprivileged then queue a task to obtain a permit first.
        if (isPrivileged) {
            obtain.run();
            toSubmit = effectorTask;
        } else {
            Task<?> obtainMutex = Tasks.builder()
                    .description(description)
                    .body(new ObtainPermit(getChildTaskSemaphore(), description, permitObtained))
                    .build();
            toSubmit = Tasks.sequential(
                    "Waiting for permit then running " + effector.getName() + " on " + target,
                    obtainMutex, effectorTask);
        }
        toSubmit.addListener(new ReleasePermit(getChildTaskSemaphore(), permitObtained), MoreExecutors.sameThreadExecutor());
    } else {
        toSubmit = effectorTask;
    }
    return toSubmit;
}
 
Example 6
Source File: Effectors.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** creates a new effector builder to _override_ the given effector */
public static <T> EffectorBuilder<T> effector(Effector<T> base) {
    EffectorBuilder<T> builder = new EffectorBuilder<T>(base.getReturnType(), base.getName());
    for (ParameterType<?> p: base.getParameters())
        builder.parameter(p);
    builder.description(base.getDescription());
    if (base instanceof EffectorWithBody)
        builder.impl(((EffectorWithBody<T>) base).getBody());
    return builder;
}
 
Example 7
Source File: EffectorUtils.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
EffectorCallPropagatedRuntimeException(Entity entity, Effector<?> effector, Throwable throwable) {
    super(makeMessage(entity, effector), throwable);
    this.entityId = entity.getId();
    this.effectorName = effector.getName();
}
 
Example 8
Source File: EffectorUtils.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
private static String makeMessage(Entity entity, Effector<?> effector) {
    return "Error invoking " + effector.getName() + " at " + entity;
}
 
Example 9
Source File: EffectorAndBody.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public EffectorAndBody(Effector<T> original, EffectorTaskFactory<T> body) {
    this(original.getName(), original.getReturnType(), original.getParameters(), original.getDescription(), body);
}