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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations