Search in sources :

Example 21 with PlatformLayerClient

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

the class GetJobLog method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    if (jobId.contains("/") && executionId == null) {
        String[] tokens = jobId.split("/");
        if (tokens.length == 2) {
            jobId = tokens[0];
            executionId = tokens[1];
        }
    }
    List<JobLog> logs = Lists.newArrayList();
    if (Strings.isNullOrEmpty(executionId)) {
        JobExecutionList jobExecutions = client.listJobExecutions(jobId);
        List<JobExecutionData> runs = jobExecutions.getRuns();
        sort(runs);
        // TODO: Remove limit (or iterate)
        if (runs.size() > 10) {
            runs = Lists.newArrayList(runs.subList(runs.size() - 10, runs.size()));
        }
        // TODO: Fix 1+N slowness...
        for (JobExecutionData execution : runs) {
            if (execution.getState() == JobState.PRESTART) {
                continue;
            }
            String executionId = execution.getExecutionId();
            try {
                JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
                logs.add(jobLog);
            } catch (PlatformLayerClientNotFoundException e) {
            // TODO: Warn?
            }
        }
    } else {
        JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
        logs.add(jobLog);
    }
    return logs;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) PlatformLayerClientNotFoundException(org.platformlayer.PlatformLayerClientNotFoundException) JobLog(org.platformlayer.jobs.model.JobLog) JobExecutionList(org.platformlayer.jobs.model.JobExecutionList)

Example 22 with PlatformLayerClient

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

the class GetMetric method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    MetricQuery query = new MetricQuery();
    query.item = getContext().pathToItem(getProject(), path);
    if (filters != null) {
        query.filters.addAll(filters);
    }
    if (projections != null) {
        query.projections.addAll(projections);
    }
    query.setFlatten(flatten);
    MetricDataStream dataStream = client.getMetric(query);
    return dataStream;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) MetricQuery(org.platformlayer.metrics.model.MetricQuery) MetricDataStream(org.platformlayer.metrics.model.MetricDataStream)

Example 23 with PlatformLayerClient

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

the class PlatformLayerCliContext method getAllServiceInfos.

private Iterable<ServiceInfo> getAllServiceInfos() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    Iterable<ServiceInfo> allServices = client.listServices(true);
    return allServices;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) ServiceInfo(org.platformlayer.core.model.ServiceInfo)

Example 24 with PlatformLayerClient

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

the class ActionCommandBase method runAction.

protected JobData runAction(ItemPath path, Action action) throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey key = path.resolve(getContext());
    JobData ret = client.doAction(key, action);
    return ret;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) JobData(org.platformlayer.jobs.model.JobData)

Example 25 with PlatformLayerClient

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

the class SetProperty method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException, IOException {
    PlatformLayerClient client = getPlatformLayerClient();
    if (stdin) {
        if (value != null) {
            throw new CliException("You cannot specify a value when using -stdin");
        }
        InputStream stream = new NoCloseInputStream(System.in);
        byte[] data = ByteStreams.toByteArray(stream);
        if ("base64".equals(format)) {
            value = Base64.encode(data);
        } else {
            value = new String(data);
        }
    } else {
        if (value == null) {
            throw new CliException("Value is required (if not using -stdin)");
        }
    }
    return runCommand(path);
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) NoCloseInputStream(com.fathomdb.io.NoCloseInputStream) CliException(com.fathomdb.cli.CliException) NoCloseInputStream(com.fathomdb.io.NoCloseInputStream) InputStream(java.io.InputStream)

Aggregations

PlatformLayerClient (org.platformlayer.PlatformLayerClient)36 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)21 UntypedItem (org.platformlayer.common.UntypedItem)7 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)4 PlatformLayerCliContext (org.platformlayer.client.cli.PlatformLayerCliContext)4 JobData (org.platformlayer.jobs.model.JobData)4 CliException (com.fathomdb.cli.CliException)3 InputStream (java.io.InputStream)3 HttpPlatformLayerClient (org.platformlayer.HttpPlatformLayerClient)3 UntypedItemXml (org.platformlayer.UntypedItemXml)3 Tag (org.platformlayer.core.model.Tag)3 ProjectId (org.platformlayer.ids.ProjectId)3 JobExecutionList (org.platformlayer.jobs.model.JobExecutionList)3 ClientAction (com.fathomdb.cli.output.ClientAction)2 NoCloseInputStream (com.fathomdb.io.NoCloseInputStream)2 IOException (java.io.IOException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 JSONObject (org.json.JSONObject)2 EndpointInfo (org.platformlayer.core.model.EndpointInfo)2 Link (org.platformlayer.core.model.Link)2