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

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


          Target target = computeTarget.getTarget();

          /* parse the application manifest */
          String manifestAppName = null;
          ManifestParseTree manifest = null;
          IFileStore appStore = null;

          if (contentLocation != null && state == null) {

            /* check for non-manifest deployment */
            if (manifestJSON != null) {

              ParseManifestJSONCommand parseManifestJSONCommand = new ParseManifestJSONCommand(manifestJSON, userId, contentLocation);
              status = parseManifestJSONCommand.doIt();
              if (!status.isOK())
                return status;

              /* get the manifest name */
              manifest = parseManifestJSONCommand.getManifest();
              appStore = parseManifestJSONCommand.getAppStore();

              if (manifest != null) {
                ManifestParseTree applications = manifest.get(CFProtocolConstants.V2_KEY_APPLICATIONS);
                if (applications.getChildren().size() > 0)
                  manifestAppName = applications.get(0).get(CFProtocolConstants.V2_KEY_NAME).getValue();

                if (persistManifest) {
                  /* non-manifest deployment - persist at contentLocation/manifest.yml */
                  IFileStore persistBaseLocation = parseManifestJSONCommand.getPersistBaseLocation();
                  IFileStore persistLocation = persistBaseLocation.getChild(ManifestConstants.MANIFEST_FILE_NAME);
                  manifest.persist(persistLocation);
                }
              }

            } else {

              ParseManifestCommand parseManifestCommand = new ParseManifestCommand(target, userId, contentLocation);
              status = parseManifestCommand.doIt();
              if (!status.isOK())
                return status;

              /* get the manifest name */
              manifest = parseManifestCommand.getManifest();
              appStore = parseManifestCommand.getAppStore();

              if (manifest != null) {
                ManifestParseTree applications = manifest.get(CFProtocolConstants.V2_KEY_APPLICATIONS);
                if (applications.getChildren().size() > 0)
                  manifestAppName = applications.get(0).get(CFProtocolConstants.V2_KEY_NAME).getValue();
              }

            }
          }

View Full Code Here


    try {

      if (manifest == null)
        manifest = ManifestUtils.createBoilerplate(getApplicationName(contentLocation));

      ManifestParseTree application = manifest.get(ManifestConstants.APPLICATIONS).get(0);
      String defaultName = getApplicationName(contentLocation);

      set(application, ManifestConstants.NAME, defaultName);
      set(application, ManifestConstants.HOST, ManifestUtils.slugify(defaultName));

      set(application, ManifestConstants.MEMORY, ManifestUtils.DEFAULT_MEMORY);
      set(application, ManifestConstants.INSTANCES, ManifestUtils.DEFAULT_INSTANCES);
      set(application, ManifestConstants.PATH, ManifestUtils.DEFAULT_PATH);

      /* node.js application require a start command */
      if (application.has(ManifestConstants.COMMAND))
        return new Plan(getId(), getWizardId(), TYPE, manifest);

      InputStream is = null;
      try {

        is = packageStore.openInputStream(EFS.NONE, null);
        JSONObject packageJSON = new JSONObject(new JSONTokener(new InputStreamReader(is)));
        if (packageJSON.has(NodeJSConstants.SCRIPTS)) {
          JSONObject scripts = packageJSON.getJSONObject(NodeJSConstants.SCRIPTS);
          if (scripts.has(NodeJSConstants.START)) {
            application.put(ManifestConstants.COMMAND, scripts.getString(NodeJSConstants.START));
            return new Plan(getId(), getWizardId(), TYPE, manifest);
          }
        }

      } catch (JSONException ex) {
        /* can't parse the package.json, fail */
        return null;

      } finally {
        IOUtilities.safeClose(is);
      }

      /* look for server.js or app.js files */
      IFileStore serverJS = contentLocation.getChild(NodeJSConstants.SERVER_JS);
      if (serverJS.fetchInfo().exists()) {
        application.put(ManifestConstants.COMMAND, NodeJSConstants.NODE_SERVER_JS);
        return new Plan(getId(), getWizardId(), TYPE, manifest);
      }

      IFileStore appJS = contentLocation.getChild(NodeJSConstants.APP_JS);
      if (appJS.fetchInfo().exists()) {
        application.put(ManifestConstants.COMMAND, NodeJSConstants.NODE_APP_JS);
        return new Plan(getId(), getWizardId(), TYPE, manifest);
      }

      /* could not deduce command, mark as required */
      Plan plan = new Plan(getId(), getWizardId(), TYPE, manifest);
View Full Code Here

  @Override
  public List<Plan> getDeploymentPlans(IFileStore contentLocation, ManifestParseTree manifest) {
    List<Plan> plans = new ArrayList<Plan>();
    for (IDeploymentPlanner planner : planners) {
      Plan plan = planner.getDeploymentPlan(contentLocation, manifest != null ? new ManifestParseTree(manifest) : null);
      if (plan != null)
        plans.add(plan);
    }

    return plans;
View Full Code Here

      if (manifest == null)
        manifest = ManifestUtils.createBoilerplate(applicationName);

      /* set up generic defaults */
      ManifestParseTree application = manifest.get(ManifestConstants.APPLICATIONS).get(0);
      set(application, ManifestConstants.HOST, ManifestUtils.slugify(applicationName));
      set(application, ManifestConstants.MEMORY, ManifestUtils.DEFAULT_MEMORY);
      set(application, ManifestConstants.INSTANCES, ManifestUtils.DEFAULT_INSTANCES);
      set(application, ManifestConstants.PATH, ManifestUtils.DEFAULT_PATH);
      return new Plan(getId(), getWizardId(), TYPE, manifest);
View Full Code Here

          ParseManifestCommand parseManifestCommand = new ParseManifestCommand(null, userId, path);
          IStatus status = parseManifestCommand.doIt();
          if (!status.isOK())
            return status;

          ManifestParseTree manifest = parseManifestCommand.getManifest();
          Manifest resp = new Manifest(manifest);

          return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, resp.toJSON());

        } catch (Exception e) {
View Full Code Here

          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

TOP

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

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.