Search in sources :

Example 26 with PlatformLayerClient

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

the class TailLog method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException, InterruptedException {
    PlatformLayerClient client = getPlatformLayerClient();
    // TODO: System.out isn't quite right
    JobLogPrinter jobLogPrinter = new JobLogPrinter(new PrintWriter(System.out));
    if (Strings.isNullOrEmpty(executionId)) {
        JobExecutionList jobExecutions = client.listJobExecutions(jobId);
        JobExecutionData last = null;
        for (JobExecutionData execution : jobExecutions.getRuns()) {
            if (execution.getState() == JobState.PRESTART) {
                continue;
            }
            if (last == null) {
                last = execution;
                continue;
            }
            if (last.getStartedAt().before(execution.getStartedAt())) {
                last = execution;
                continue;
            }
        }
        if (last != null) {
            executionId = last.getExecutionId();
        }
    }
    // TODO: What if executionId == null? Also retries..
    JobLog previousJobLog = null;
    int jobLogOffset = 0;
    while (true) {
        // TODO: Only fetch tail
        JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
        if (previousJobLog == null) {
            jobLogPrinter.startJobLog(jobLog);
        }
        List<JobLogLine> lines = jobLog.getLines();
        if (jobLogOffset < lines.size()) {
            for (JobLogLine line : lines.subList(jobLogOffset, lines.size())) {
                jobLogPrinter.write(line);
            }
        }
        jobLogPrinter.flush();
        jobLogOffset = lines.size();
        previousJobLog = jobLog;
        Thread.sleep(1000);
    }
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobLogLine(org.platformlayer.jobs.model.JobLogLine) JobLog(org.platformlayer.jobs.model.JobLog) JobExecutionList(org.platformlayer.jobs.model.JobExecutionList) PrintWriter(java.io.PrintWriter)

Example 27 with PlatformLayerClient

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

the class ListMetrics method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey key = getContext().pathToItem(getProject(), path);
    MetricInfoCollection items = client.listMetrics(key);
    return items;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) MetricInfoCollection(org.platformlayer.metrics.model.MetricInfoCollection)

Example 28 with PlatformLayerClient

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

the class ListTags method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    PlatformLayerKey key = path.resolve(getContext());
    UntypedItem ret = client.getItemUntyped(key, getFormat());
    return ret.getTags();
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) UntypedItem(org.platformlayer.common.UntypedItem) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 29 with PlatformLayerClient

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

the class ScriptCommands method activateService.

public static Object activateService(String serviceType, Object properties) throws PlatformLayerClientException, JSONException {
    PlatformLayerCliContext context = PlatformLayerCliContext.get();
    PlatformLayerClient client = context.getPlatformLayerClient();
    String json = properties.toString();
    String wrapper = "{ \"data\": \"" + json + "\" }";
    String retvalJsonString = client.activateService(serviceType, wrapper, Format.JSON);
    JSONObject retvalJsonObject = new JSONObject(retvalJsonString);
    return toPython(retvalJsonObject);
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) JSONObject(org.codehaus.jettison.json.JSONObject) PlatformLayerCliContext(org.platformlayer.client.cli.PlatformLayerCliContext)

Example 30 with PlatformLayerClient

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

the class ScriptCommands method getSchema.

public static Object getSchema(String serviceType) throws PlatformLayerClientException, JSONException {
    PlatformLayerCliContext context = PlatformLayerCliContext.get();
    PlatformLayerClient client = context.getPlatformLayerClient();
    String retval = client.getSchema(serviceType, Format.XML);
    return retval;
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) PlatformLayerCliContext(org.platformlayer.client.cli.PlatformLayerCliContext)

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