Package org.eclipse.orion.server.cf.manifest.v2

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


          IFileStore contentLocation = NewFileServlet.getFileStore(null, contentPath.removeFirstSegments(1));
          if (!contentLocation.fetchInfo().isDirectory())
            contentLocation = contentLocation.getParent();

          /* check if the application has a manifest */
          ManifestParseTree manifest = null;
          ParseManifestCommand parseManifestCommand = new ParseManifestCommand(null, userId, contentPath.toString()); /* TODO: set target */
          parseManifestCommand.setApplicationAnalyzer(new ApplicationReconstructor());

          IStatus status = parseManifestCommand.doIt();
          if (status.isOK())
View Full Code Here


      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

      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

    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

  @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

  @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

  @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

        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

    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

    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

TOP

Related Classes of org.eclipse.orion.server.cf.manifest.v2.ParserException

Copyright © 2018 www.massapicom. 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.