Examples of PlatformLayerClient


Examples of org.platformlayer.PlatformLayerClient

    if (target == null) {
      throw new IllegalArgumentException("Unknown key: " + key);
    }

    if (target.client == null) {
      PlatformLayerClient client = HttpPlatformLayerClient.buildUsingConfiguration(httpStrategy,
          target.configuration);

      TypedPlatformLayerClient typedClient = new TypedPlatformLayerClient(client, mapper);
      // TODO: Save client??
      return typedClient;
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

    }
    return services;
  }

  private Iterable<ServiceInfo> getAllServiceInfos() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();
    Iterable<ServiceInfo> allServices = client.listServices(true);
    return allServices;
  }
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

      json = data.toString();
    } catch (JSONException e) {
      throw new IllegalStateException("Error building JSON", e);
    }

    PlatformLayerClient client = getPlatformLayerClient();

    PlatformLayerKey key = path.resolve(getContext());

    JobData ret = client.doAction(key, json, Format.JSON);
    return ret;
  }
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

    super("put", "item");
  }

  @Override
  public Object runCommand() throws PlatformLayerClientException, JSONException {
    PlatformLayerClient client = getPlatformLayerClient();

    if (json == null) {
      InputStream stream = new NoCloseInputStream(System.in);
      byte[] data;
      try {
        data = ByteStreams.toByteArray(stream);

        json = new String(data, Charsets.UTF_8);
      } catch (IOException e) {
        throw new CliException("Error reading stdin", e);
      }
    }

    JSONObject jsonObject = new JSONObject(json);

    PlatformLayerKey parentKey = null;
    if (parent != null || !tags.isEmpty()) {

      JSONObject tagsObject = null;
      if (jsonObject.has("tags")) {
        tagsObject = jsonObject.getJSONObject("tags");
      } else {
        tagsObject = new JSONObject();
        jsonObject.put("tags", tagsObject);
      }

      JSONArray tagsArray;
      if (tagsObject.has("tags")) {
        tagsArray = tagsObject.getJSONArray("tags");
      } else {
        tagsArray = new JSONArray();
        tagsObject.put("tags", tagsArray);
      }

      if (parent != null) {
        parentKey = parent.resolve(getContext());
        Tag parentTag = Tag.buildParentTag(parentKey);

        JSONObject jsonTag = new JSONObject();
        jsonTag.put("key", parentTag.getKey());
        jsonTag.put("value", parentTag.getValue());

        tagsArray.put(jsonTag);
      }

      for (String tag : tags) {
        int equalsIndex = tag.indexOf('=');
        if (equalsIndex == -1) {
          throw new CliException("Expected tagname=tagvalue");
        }

        String tagName = tag.substring(0, equalsIndex);
        String tagValue = tag.substring(equalsIndex + 1);

        JSONObject jsonTag = new JSONObject();
        jsonTag.put("key", tagName);
        jsonTag.put("value", tagValue);

        tagsArray.put(jsonTag);
      }
    }

    PlatformLayerKey key = path.resolve(getContext());

    boolean wrap = false;
    String data;
    if (wrap) {
      JSONObject wrapped = new JSONObject();
      wrapped.put(key.getItemType().getKey(), jsonObject);

      data = wrapped.toString();
    } else {
      data = jsonObject.toString();
    }

    UntypedItem retval = client.putItem(key, data, Format.JSON);

    return retval;
  }
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

import com.google.common.collect.Lists;

public class AutoCompleteJobId extends PlatformLayerSimpleAutoCompleter {
  @Override
  public List<String> doComplete(CliContext context, String prefix) throws Exception {
    PlatformLayerClient client = getPlatformLayerClient(context);
    List<String> jobs = Lists.newArrayList();
    for (JobData jobData : client.listJobs().getJobs()) {
      jobs.add(jobData.getJobId());
    }
    addSuffix(jobs, " ");
    return jobs;
  }
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

    super("delete", "tag");
  }

  @Override
  public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();

    PlatformLayerKey key = path.resolve(getContext());
    UntypedItem ret = client.getItemUntyped(key, Format.XML);

    TagChanges tagChanges = new TagChanges();
    for (Tag tag : ret.getTags()) {
      if (!tagKey.equals(tag.getKey())) {
        continue;
      }

      if (tagValue != null && !tagValue.equals(tag.getValue())) {
        continue;
      }

      tagChanges.removeTags.add(tag);
    }

    Tags newTags = client.changeTags(key, tagChanges, null);
    return newTags;
  }
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

    PlatformLayerCliContext plContext = (PlatformLayerCliContext) context;
    return plContext.getPlatformLayerClient();
  }

  protected List<String> listItems(CliContext context, String itemType) throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient(context);
    PlatformLayerKey key = PlatformLayerCommandRunnerBase.pathToKey(client, itemType);

    List<String> items = Lists.newArrayList();
    for (UntypedItem item : client.listItemsUntyped(key).getItems()) {
      items.add(item.getKey().getItemId().getKey());
    }
    return items;
  }
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

    super("add", "tag");
  }

  @Override
  public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();

    PlatformLayerKey resolved = path.resolve(getContext());

    TagChanges tagChanges = new TagChanges();
    Tag tag = Tag.build(tagKey, tagValue);
    tagChanges.addTags.add(tag);

    return client.changeTags(resolved, tagChanges, null);
  }
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

    super("list", "services");
  }

  @Override
  public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();

    return client.listServices(true);
  }
View Full Code Here

Examples of org.platformlayer.PlatformLayerClient

    super("list", "metrics");
  }

  @Override
  public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();

    PlatformLayerKey key = getContext().pathToItem(getProject(), path);

    MetricInfoCollection items = client.listMetrics(key);

    return items;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.