Examples of PlatformLayerKey


Examples of org.platformlayer.core.model.PlatformLayerKey

  @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);
View Full Code Here

Examples of org.platformlayer.core.model.PlatformLayerKey

  public static String reformatText(PlatformLayerCliContext context, String text) {
    if (text.startsWith("platform://")) {
      // This looks like a PlatformLayerKey
      try {
        PlatformLayerKey key = PlatformLayerKey.parse(text);
        text = formatUrl(context, key);
      } catch (Exception e) {
        // Ignore
      }
    }
View Full Code Here

Examples of org.platformlayer.core.model.PlatformLayerKey

  }

  @Override
  public <T> List<T> listItems(final Class<T> clazz) throws PlatformLayerClientException {
    JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(clazz, ManagedItemCollection.class);
    PlatformLayerKey path = PlatformLayerClientBase.toKey(jaxbHelper, null, listServices(true));

    return doListConcatenationTyped(getChildClients(path), AddHostTyped.wrap(new ListItemsTyped<T>(clazz)));
  }
View Full Code Here

Examples of org.platformlayer.core.model.PlatformLayerKey

    if (Strings.isNullOrEmpty(itemId)) {
      throw new IllegalArgumentException("Cannot resolve path (item id not resolved): " + path);
    }

    FederationKey host = null;
    return new PlatformLayerKey(host, project, new ServiceType(serviceType), new ItemType(itemType),
        new ManagedItemId(itemId));
  }
View Full Code Here

Examples of org.platformlayer.core.model.PlatformLayerKey

      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.core.model.PlatformLayerKey

    DirectCloudHost candidate;
  }

  PlatformLayerKey findOwner(DirectInstance instance) throws OpsException {
    PlatformLayerKey parentKey = Tag.PARENT.findUnique(instance);
    if (parentKey != null) {
      ItemBase persistentInstance = platformLayer.getItem(parentKey);

      if (persistentInstance != null) {
        PlatformLayerKey grandparentKey = Tag.PARENT.findUnique(instance);
        return grandparentKey;
      }
    }
    return null;
  }
View Full Code Here

Examples of org.platformlayer.core.model.PlatformLayerKey

    } else {
      sameGroupId = hostPolicy.groupId;
    }
    final ItemType sameItemType;
    if (hostPolicy.scoreSameItemType != 0) {
      PlatformLayerKey owner = findOwner(newInstance);
      if (owner == null) {
        throw new OpsException();
      }

      sameItemType = owner.getItemType();
    } else {
      sameItemType = null;
    }

    List<HostRecord> records = Lists.newArrayList();
    for (DirectCloudHost candidate : candidates) {
      HostRecord record = new HostRecord();
      record.candidate = candidate;
      record.groups = Maps.newHashMap();
      if (hostPolicy.scoreSameItemType != 0) {
        record.owners = Maps.newHashMap();
      }
      records.add(record);

      for (String assigned : candidate.getModel().getTags().findAll(Tag.ASSIGNED)) {
        PlatformLayerKey instanceKey = PlatformLayerKey.parse(assigned);

        // TODO: Avoid 1+N
        DirectInstance instance = platformLayer.getItem(instanceKey);
        if (instance == null) {
          // TODO: Warn?
          throw new IllegalStateException();
        }

        switch (instance.getState()) {
        case DELETE_REQUESTED:
        case DELETED:
          continue;
        }

        HostPolicy instanceHostPolicy = instance.hostPolicy;
        String instanceGroupId = instanceHostPolicy.groupId;
        if (Strings.isNullOrEmpty(instanceGroupId)) {
          instanceGroupId = DEFAULT_GROUP;
        }

        record.groups.put(instance, instanceGroupId);

        if (sameItemType != null) {
          PlatformLayerKey owner = findOwner(instance);
          if (owner != null) {
            record.owners.put(instance, owner);
          }
        }

        record.all.add(instance);
      }
    }

    Function<HostRecord, Float> score = new Function<HostRecord, Float>() {
      @Override
      public Float apply(HostRecord record) {
        float score = 0;

        for (DirectInstance instance : record.all) {
          if (sameGroupId != null) {
            String instanceGroupId = record.groups.get(instance);
            if (Objects.equal(instanceGroupId, sameGroupId)) {
              score += hostPolicy.scoreSameGroup;
            }
          }

          if (sameItemType != null) {
            PlatformLayerKey owner = record.owners.get(instance);

            if (owner != null && owner.getItemType().equals(sameItemType)) {
              score += hostPolicy.scoreSameItemType;
            }
          }
        }
View Full Code Here

Examples of org.platformlayer.core.model.PlatformLayerKey

      }
    }

    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();
    }
View Full Code Here

Examples of org.platformlayer.core.model.PlatformLayerKey

      HostRecord record = new HostRecord();
      record.candidate = candidate;
      records.add(record);

      for (String assigned : candidate.getModel().getTags().findAll(Tag.ASSIGNED)) {
        PlatformLayerKey instanceKey = PlatformLayerKey.parse(assigned);

        // TODO: Avoid 1+N
        DirectInstance instance = platformLayer.getItem(instanceKey);
        if (instance == null) {
          // TODO: Warn?
View Full Code Here

Examples of org.platformlayer.core.model.PlatformLayerKey

  @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())) {
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.