Search in sources :

Example 1 with PlatformLayerEndpointInfo

use of org.platformlayer.PlatformLayerEndpointInfo in project platformlayer by platformlayer.

the class SchedulerImpl method toRunnable.

private Runnable toRunnable(final ActionTask task) {
    final PlatformLayerKey target = task.target;
    final PlatformLayerEndpointInfo endpoint = rehydrateEndpoint(task.endpoint);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                PlatformLayerClient platformLayer = HttpPlatformLayerClient.build(httpStrategy, endpoint.getPlatformlayerBaseUrl(), endpoint.getAuthenticator(), endpoint.getProjectId(), endpoint.getTrustKeys());
                platformLayer.doAction(target, task.action);
            // TODO: Wait for task completion??
            // TODO: Link job id??
            } catch (PlatformLayerClientException e) {
                log.warn("Error running action", e);
            }
        }

        @Override
        public String toString() {
            return task.action + " on " + task.target;
        }
    };
    return runnable;
}
Also used : HttpPlatformLayerClient(org.platformlayer.HttpPlatformLayerClient) PlatformLayerClient(org.platformlayer.PlatformLayerClient) PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) PlatformLayerEndpointInfo(org.platformlayer.PlatformLayerEndpointInfo) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 2 with PlatformLayerEndpointInfo

use of org.platformlayer.PlatformLayerEndpointInfo in project platformlayer by platformlayer.

the class ScheduleController method handler.

@Handler
public void handler() throws OpsException {
    if (OpsContext.isConfigure()) {
        String key = model.getKey().getUrl();
        PlatformLayerKey target = model.targetItem;
        PlatformLayerEndpointInfo endpoint = platformLayer.getEndpointInfo(target);
        JobSchedule schedule = model.schedule;
        Action action = model.action;
        actionScheduler.putJob(key, endpoint, schedule, target, action);
    }
}
Also used : Action(org.platformlayer.core.model.Action) PlatformLayerEndpointInfo(org.platformlayer.PlatformLayerEndpointInfo) JobSchedule(org.platformlayer.core.model.JobSchedule) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Handler(org.platformlayer.ops.Handler)

Example 3 with PlatformLayerEndpointInfo

use of org.platformlayer.PlatformLayerEndpointInfo in project platformlayer by platformlayer.

the class SchedulerImpl method rehydrateEndpoint.

private static PlatformLayerEndpointInfo rehydrateEndpoint(final EndpointRecord in) {
    final Authenticator authenticator;
    final String platformlayerBaseUrl = in.url;
    final ProjectId projectId = new ProjectId(in.project);
    final List<String> trustKeys;
    if (Strings.isNullOrEmpty(in.trustKeys)) {
        trustKeys = Collections.emptyList();
    } else {
        trustKeys = Lists.newArrayList(Splitter.on(",").split(in.trustKeys));
    }
    {
        String token = in.token;
        CryptoKey secret = FathomdbCrypto.deserializeKey(Hex.fromHex(in.secret.plaintext()));
        DirectAuthenticationToken authenticationToken = new DirectAuthenticationToken(token, secret);
        authenticator = new DirectAuthenticator(authenticationToken);
    }
    PlatformLayerEndpointInfo out = new PlatformLayerEndpointInfo(authenticator, platformlayerBaseUrl, projectId, trustKeys);
    return out;
}
Also used : PlatformLayerEndpointInfo(org.platformlayer.PlatformLayerEndpointInfo) DirectAuthenticationToken(org.platformlayer.auth.DirectAuthenticationToken) ProjectId(org.platformlayer.ids.ProjectId) CryptoKey(com.fathomdb.crypto.CryptoKey) DirectAuthenticator(org.platformlayer.auth.DirectAuthenticator) Authenticator(org.platformlayer.auth.Authenticator) DirectAuthenticator(org.platformlayer.auth.DirectAuthenticator)

Aggregations

PlatformLayerEndpointInfo (org.platformlayer.PlatformLayerEndpointInfo)3 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 CryptoKey (com.fathomdb.crypto.CryptoKey)1 HttpPlatformLayerClient (org.platformlayer.HttpPlatformLayerClient)1 PlatformLayerClient (org.platformlayer.PlatformLayerClient)1 PlatformLayerClientException (org.platformlayer.PlatformLayerClientException)1 Authenticator (org.platformlayer.auth.Authenticator)1 DirectAuthenticationToken (org.platformlayer.auth.DirectAuthenticationToken)1 DirectAuthenticator (org.platformlayer.auth.DirectAuthenticator)1 Action (org.platformlayer.core.model.Action)1 JobSchedule (org.platformlayer.core.model.JobSchedule)1 ProjectId (org.platformlayer.ids.ProjectId)1 Handler (org.platformlayer.ops.Handler)1