Examples of ManifestParseTree


Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

      if (!result.isOK())
        return result;

      if (timeout < 0) {
        /* extract user defined timeout if present */
        ManifestParseTree manifest = app.getManifest();
        ManifestParseTree timeoutNode = manifest.get(CFProtocolConstants.V2_KEY_APPLICATIONS).get(0).getOpt(CFProtocolConstants.V2_KEY_TIMEOUT);
        timeout = (timeoutNode != null) ? Integer.parseInt(timeoutNode.getValue()) : ManifestConstants.DEFAULT_TIMEOUT;
      }

      /* long running task, keep track */
      timeout = Math.min(timeout, ManifestConstants.MAX_TIMEOUT);
      int attemptsLeft = timeout / 2;
View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

      status.add(multijobStatus);
      if (!multijobStatus.isOK())
        return status;

      /* extract user defined timeout if present */
      ManifestParseTree manifest = app.getManifest();
      ManifestParseTree timeoutNode = manifest.get(CFProtocolConstants.V2_KEY_APPLICATIONS).get(0).getOpt(CFProtocolConstants.V2_KEY_TIMEOUT);
      int timeout = (timeoutNode != null) ? Integer.parseInt(timeoutNode.getValue()) : ManifestConstants.DEFAULT_TIMEOUT;

      /* craft command result */
      JSONObject result = new JSONObject();
      result.put("Target", target.toJSON()); //$NON-NLS-1$
      if (target.getManageUrl() != null)
View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

    try {

      /* bind services */
      URI targetURI = URIUtil.toURI(target.getUrl());

      ManifestParseTree manifest = getApplication().getManifest();
      ManifestParseTree app = manifest.get("applications").get(0); //$NON-NLS-1$

      if (app.has(CFProtocolConstants.V2_KEY_SERVICES)) {

        /* fetch all services */
        URI servicesURI = targetURI.resolve("/v2/services"); //$NON-NLS-1$
        GetMethod getServicesMethod = new GetMethod(servicesURI.toString());
        HttpUtil.configureHttpMethod(getServicesMethod, target);
        getServicesMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$

        /* send request */
        ServerStatus jobStatus = HttpUtil.executeMethod(getServicesMethod);
        status.add(jobStatus);
        if (!jobStatus.isOK())
          return status;

        JSONObject resp = jobStatus.getJsonData();
        JSONArray servicesJSON = resp.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES);

        /* check for manifest version */
        ManifestParseTree services = app.getOpt(CFProtocolConstants.V2_KEY_SERVICES);
        if (services == null)
          /* nothing to do */
          return status;

        int version = services.isList() ? 6 : 2;

        if (version == 2) {
          String spaceGuid = target.getSpace().getGuid();
          URI serviceInstancesURI2 = targetURI.resolve("/v2/spaces/" + spaceGuid + "/service_instances"); //$NON-NLS-1$//$NON-NLS-2$

          for (ManifestParseTree service : services.getChildren()) {
            String serviceName = service.getLabel();

            String nameService = "name:" + serviceName; //$NON-NLS-1$
            NameValuePair[] pa = new NameValuePair[] {new NameValuePair("return_user_provided_service_instances", "true"), //  //$NON-NLS-1$//$NON-NLS-2$
                new NameValuePair("q", nameService), new NameValuePair("inline-relations-depth", "1") //  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            };

            GetMethod getServiceMethod = new GetMethod(serviceInstancesURI2.toString());
            getServiceMethod.setQueryString(pa);
            HttpUtil.configureHttpMethod(getServiceMethod, target);

            /* send request */
            jobStatus = HttpUtil.executeMethod(getServiceMethod);
            status.add(jobStatus);
            if (!jobStatus.isOK())
              return status;

            resp = jobStatus.getJsonData();
            String serviceInstanceGUID = null;
            JSONArray respArray = resp.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES);
            for (int i = 0; i < respArray.length(); ++i) {
              JSONObject o = respArray.optJSONObject(i);
              if (o != null) {
                JSONObject str = o.optJSONObject(CFProtocolConstants.V2_KEY_METADATA);
                if (str != null) {
                  serviceInstanceGUID = str.getString(CFProtocolConstants.V2_KEY_GUID);
                  break;
                }
              }
            }

            if (serviceInstanceGUID == null) {
              /* no service instance bound to the application, create one if possible */

              /* support both 'type' and 'label' fields as service type */
              ManifestParseTree serviceType = service.getOpt(CFProtocolConstants.V2_KEY_TYPE);
              if (serviceType == null)
                serviceType = service.get(CFProtocolConstants.V2_KEY_LABEL);

              ManifestParseTree provider = service.get(CFProtocolConstants.V2_KEY_PROVIDER);
              ManifestParseTree plan = service.get(CFProtocolConstants.V2_KEY_PLAN);

              String servicePlanGUID = findServicePlanGUID(serviceType.getValue(), provider.getValue(), plan.getValue(), servicesJSON);
              if (servicePlanGUID == null) {
                String[] bindings = {serviceName, serviceType.getValue(), plan.getValue()};
                String msg = NLS.bind("Could not find service instance {0} nor service {1} with plan {2} in target.", bindings);
                status.add(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
                return status;
              }

View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

  @Override
  protected IStatus validateParams() {
    try {

      /* read deploy parameters */
      ManifestParseTree manifest = application.getManifest();
      ManifestParseTree app = manifest.get(CFProtocolConstants.V2_KEY_APPLICATIONS).get(0);

      if (application.getName() != null)
        appName = application.getName();
      else
        appName = app.get(CFProtocolConstants.V2_KEY_NAME).getValue();

      ManifestParseTree commandNode = app.getOpt(CFProtocolConstants.V2_KEY_COMMAND);
      appCommand = (commandNode != null) ? commandNode.getValue() : ""; //$NON-NLS-1$

      ManifestParseTree instancesNode = app.getOpt(CFProtocolConstants.V2_KEY_INSTANCES);
      appInstances = (instancesNode != null) ? Integer.parseInt(instancesNode.getValue()) : 1;

      /* look for v2 memory property first */
      ManifestParseTree memoryNode = app.getOpt(CFProtocolConstants.V2_KEY_MEMORY);
      if (memoryNode != null)
        appMemory = ManifestUtils.normalizeMemoryMeasure(memoryNode.getValue());
      else {
        memoryNode = app.getOpt(CFProtocolConstants.V6_KEY_MEMORY);
        if (memoryNode != null)
          appMemory = ManifestUtils.normalizeMemoryMeasure(memoryNode.getValue());
        else
          /* default memory value */
          appMemory = 1024;
      }

      ManifestParseTree buildpackNode = app.getOpt(CFProtocolConstants.V2_KEY_BUILDPACK);
      buildPack = (buildpackNode != null) ? buildpackNode.getValue() : null;

      /* look for environment variables */
      ManifestParseTree envNode = manifest.getOpt(CFProtocolConstants.V2_KEY_ENV);
      if (envNode != null) {
        env = new JSONObject();
        for (ManifestParseTree var : envNode.getChildren())
          env.put(var.getLabel(), var.getValue());
      }

      return Status.OK_STATUS;

View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

  @Override
  protected IStatus validateParams() {
    try {
      /* read deploy parameters */
      ManifestParseTree manifest = app.getManifest();
      ManifestParseTree manifestApp = manifest.get("applications").get(0); //$NON-NLS-1$

      if (app.getName() != null) {
        appName = app.getName();
        return Status.OK_STATUS;
      }

      appName = manifestApp.get(CFProtocolConstants.V2_KEY_NAME).getValue();
      return Status.OK_STATUS;
    } catch (InvalidAccessException e) {
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), null);
    }
  }
View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

  @Override
  protected IStatus validateParams() {
    try {
      /* read deploy parameters */
      ManifestParseTree manifest = application.getManifest();
      ManifestParseTree app = manifest.get(CFProtocolConstants.V2_KEY_APPLICATIONS).get(0);

      if (application.getName() != null)
        appName = application.getName();
      else
        appName = app.get(CFProtocolConstants.V2_KEY_NAME).getValue();

      ManifestParseTree commandNode = app.getOpt(CFProtocolConstants.V2_KEY_COMMAND);
      appCommand = (commandNode != null) ? commandNode.getValue() : ""; //$NON-NLS-1$

      ManifestParseTree instancesNode = app.getOpt(CFProtocolConstants.V2_KEY_INSTANCES);
      appInstances = (instancesNode != null) ? Integer.parseInt(instancesNode.getValue()) : 1;

      /* look for v2 memory property first */
      ManifestParseTree memoryNode = app.getOpt(CFProtocolConstants.V2_KEY_MEMORY);
      if (memoryNode != null)
        appMemory = ManifestUtils.normalizeMemoryMeasure(memoryNode.getValue());
      else {
        memoryNode = app.getOpt(CFProtocolConstants.V6_KEY_MEMORY);
        if (memoryNode != null)
          appMemory = ManifestUtils.normalizeMemoryMeasure(memoryNode.getValue());
        else
          /* default memory value */
          appMemory = 1024;
      }

      ManifestParseTree buildpackNode = app.getOpt(CFProtocolConstants.V2_KEY_BUILDPACK);
      buildPack = (buildpackNode != null) ? buildpackNode.getValue() : null;

      /* look for environment variables */
      ManifestParseTree envNode = manifest.getOpt(CFProtocolConstants.V2_KEY_ENV);
      if (envNode != null) {
        env = new JSONObject();
        for (ManifestParseTree var : envNode.getChildren())
          env.put(var.getLabel(), var.getValue());
      }

      return Status.OK_STATUS;

View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

        return Status.OK_STATUS;
      else if (app == null && hostName == null)
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Missing host name parameter", null);

      /* read deploy parameters */
      ManifestParseTree manifest = app.getManifest();
      ManifestParseTree appNode = manifest.get("applications").get(0); //$NON-NLS-1$

      String appName = null;
      if (app.getName() != null)
        appName = app.getName();
      else
        appName = appNode.get(CFProtocolConstants.V2_KEY_NAME).getValue();

      /* if none provided, generate a default one */
      ManifestParseTree hostNode = appNode.getOpt(CFProtocolConstants.V2_KEY_HOST);
      hostName = (hostNode != null) ? hostNode.getValue() : ManifestUtils.slugify(appName);

      return Status.OK_STATUS;
    } catch (InvalidAccessException e) {
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), null);
    }
View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

    URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
    File manifestFile = new File(FileLocator.toFileURL(entry).getPath().concat(manifestName));

    InputStream inputStream = new FileInputStream(manifestFile);
    ManifestParseTree manifest = parse(inputStream);

    ManifestParseTree application = manifest.get("applications").get(0); //$NON-NLS-1$
    ManifestParseTree path = application.get("path"); //$NON-NLS-1$

    assertEquals(".", path.getValue()); //$NON-NLS-1$

    ManifestParseTree host = application.get("host"); //$NON-NLS-1$
    assertEquals("quoted-path-application", host.getValue()); //$NON-NLS-1$

    ManifestParseTree domain = application.get("domain"); //$NON-NLS-1$

    assertEquals("cloud-foundry-domain.org", domain.getValue()); //$NON-NLS-1$
  }
View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

    URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
    File manifestFile = new File(FileLocator.toFileURL(entry).getPath().concat(manifestName));

    InputStream inputStream = new FileInputStream(manifestFile);
    ManifestParseTree manifest = parse(inputStream);
    SymbolResolver resolver = new SymbolResolver("api.sauron.mordor.com"); //$NON-NLS-1$
    resolver.apply(manifest);

    assertEquals("api.sauron.mordor.com", manifest.get("applications").get(0).get("domain").getValue()); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
    assertTrue(manifest.get("applications").get(0).get("url").getValue().endsWith(".api.sauron.mordor.com")); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
  }
View Full Code Here

Examples of org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree

    String manifestName = "01.yml"; //$NON-NLS-1$
    File manifestFile = new File(FileLocator.toFileURL(entry).getPath().concat(manifestName));

    InputStream inputStream = new FileInputStream(manifestFile);
    ManifestParseTree manifest = parse(inputStream);

    ManifestTransformator transformator = new ManifestTransformator();
    transformator.apply(manifest);

    ManifestParseTree applications = manifest.get("applications"); //$NON-NLS-1$
    for (ManifestParseTree application : applications.getChildren())
      assertTrue(application.get("propertyA").getValue().equals("valueA") && application.get("propertyB").getValue().equals("valueB")); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$

    manifestName = "02.yml"; //$NON-NLS-1$
    manifestFile = new File(FileLocator.toFileURL(entry).getPath().concat(manifestName));

    inputStream = new FileInputStream(manifestFile);
    manifest = parse(inputStream);

    transformator = new ManifestTransformator();
    transformator.apply(manifest);

    applications = manifest.get("applications"); //$NON-NLS-1$
    assertEquals("nativeA", applications.get(0).get("A").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("nativeB", applications.get(0).get("B").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("overriddenC", applications.get(0).get("C").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("valueD", applications.get(0).get("D").get("overriddenD").getValue()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$

    assertEquals("overriddenA", applications.get(1).get("A").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("nativeB", applications.get(1).get("B").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("nativeC", applications.get(1).get("C").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("valueD", applications.get(1).get("D").get("overriddenD").getValue()); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$

    assertEquals("nativeA", applications.get(2).get("A").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("overriddenB", applications.get(2).get("B").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("nativeC", applications.get(2).get("C").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("valueD", applications.get(2).get("D").get("overriddenD").getValue()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$

    assertEquals("overriddenA", applications.get(3).get("A").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("overriddenB", applications.get(3).get("B").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("overriddenC", applications.get(3).get("C").getValue()); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals("valueD", applications.get(3).get("D").get("nativeD").getValue()); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
  }
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.