Package org.cloudfoundry.ide.eclipse.server.core

Examples of org.cloudfoundry.ide.eclipse.server.core.ApplicationDeploymentInfo


   * available.
   * @throws CoreException if error occurred while writing to a Manifest file.
   */
  public boolean write(IProgressMonitor monitor, ApplicationDeploymentInfo previousInfo) throws CoreException {

    ApplicationDeploymentInfo deploymentInfo = appModule.getDeploymentInfo();

    if (deploymentInfo == null) {
      return false;
    }

    // Fetch the previous name, in case the app name was changed. This will
    // allow the old
    // entry to be replaced by the new one, since application entries are
    // looked up by application name.
    String previousName = previousInfo != null ? previousInfo.getDeploymentName() : null;

    String appName = deploymentInfo.getDeploymentName();

    Map<Object, Object> deploymentInfoYaml = parseManifestFromFile();

    if (deploymentInfoYaml == null) {
      deploymentInfoYaml = new LinkedHashMap<Object, Object>();
    }

    Object applicationsObj = deploymentInfoYaml.get(APPLICATIONS_PROP);
    List<Map<Object, Object>> applicationsList = null;
    if (applicationsObj == null) {
      applicationsList = new ArrayList<Map<Object, Object>>();
      deploymentInfoYaml.put(APPLICATIONS_PROP, applicationsList);
    }
    else if (applicationsObj instanceof List<?>) {
      applicationsList = (List<Map<Object, Object>>) applicationsObj;
    }
    else {
      throw CloudErrorUtil.toCoreException("Expected a top-level list of applications in: " + relativePath //$NON-NLS-1$
          + ". Unable to continue writing manifest values."); //$NON-NLS-1$
    }

    Map<Object, Object> applicationWithSameName = null;

    Map<Object, Object> oldApplication = null;

    // Each application listing should be a map. Find both an entry with the
    // same name as the application name
    // As well as an entry with an older name of the application, in case
    // the application has changed.
    for (Object appMap : applicationsList) {
      if (appMap instanceof Map<?, ?>) {
        Map<Object, Object> properties = (Map<Object, Object>) appMap;
        String name = getStringValue(properties, NAME_PROP);
        if (appName.equals(name)) {
          applicationWithSameName = properties;
        }
        else if (previousName != null && previousName.equals(name)) {
          oldApplication = properties;
        }
      }
    }

    // The order of priority in terms of replacing an existing entry is : 1.
    // old application entry that
    // has been changed will get replaced 2. existing entry with same name
    // as app will now get replaced2.
    Map<Object, Object> application = oldApplication != null ? oldApplication : applicationWithSameName;

    if (application == null) {
      application = new LinkedHashMap<Object, Object>();
      applicationsList.add(application);
    }

    application.put(NAME_PROP, appName);

    String memory = getMemoryAsString(deploymentInfo.getMemory());
    if (memory != null) {
      application.put(MEMORY_PROP, memory);
    }

    int instances = deploymentInfo.getInstances();
    if (instances > 0) {
      application.put(INSTANCES_PROP, instances);
    }

    List<String> urls = deploymentInfo.getUris();
    if (urls != null && !urls.isEmpty()) {
      // Persist only the first URL
      String url = urls.get(0);

      ApplicationUrlLookupService lookup = ApplicationUrlLookupService.getCurrentLookup(cloudServer);
      CloudApplicationURL cloudUrl = lookup.getCloudApplicationURL(url);
      String subdomain = cloudUrl.getSubdomain();
      String domain = cloudUrl.getDomain();

      if (subdomain != null) {
        application.put(SUB_DOMAIN_PROP, subdomain);
      }

      if (domain != null) {
        application.put(DOMAIN_PROP, domain);
      }
    }

    List<EnvironmentVariable> envvars = deploymentInfo.getEnvVariables();

    Map<Object, Object> varMap = new LinkedHashMap<Object, Object>();

    // Clear the list of environment variables first.
    application.put(ENV_PROP, varMap);
    if (envvars != null) {
      for (EnvironmentVariable var : envvars) {
        varMap.put(var.getVariable(), var.getValue());
      }
    }

    Staging staging = deploymentInfo.getStaging();
    if (staging != null && staging.getBuildpackUrl() != null) {
      application.put(BUILDPACK_PROP, staging.getBuildpackUrl());
    }

    String archiveURL = deploymentInfo.getArchive();
    if (archiveURL != null) {
      application.put(PATH_PROP, archiveURL);
    }

    // Regardless if there are services or not, always clear list of
    // services in the manifest, and replace with new list. The list of
    // services in the
    // deployment info has to match the content in the manifest.

    Map<Object, Object> services = new LinkedHashMap<Object, Object>();
    application.put(SERVICES_PROP, services);

    List<CloudService> servicesToBind = deploymentInfo.getServices();

    if (servicesToBind != null) {

      for (CloudService service : servicesToBind) {
        String serviceName = service.getName();
View Full Code Here


   * org.eclipse.core.runtime.IProgressMonitor)
   */
  @Override
  public ApplicationDeploymentInfo getDefaultApplicationDeploymentInfo(CloudFoundryApplicationModule appModule,
      CloudFoundryServer cloudServer, IProgressMonitor monitor) throws CoreException {
    ApplicationDeploymentInfo info = super.getDefaultApplicationDeploymentInfo(appModule, cloudServer, monitor);

    // Set a default URL for the application.
    if ((info.getUris() == null || info.getUris().isEmpty()) && info.getDeploymentName() != null) {

      CloudApplicationURL url = ApplicationUrlLookupService.update(cloudServer, monitor)
          .getDefaultApplicationURL(info.getDeploymentName());
      info.setUris(Arrays.asList(url.getUrl()));
    }
    return info;
  }
View Full Code Here

    RepublishModule repModule = CloudFoundryPlugin.getModuleCache().getData(server.getServerOriginal())
        .untagForAutomaticRepublish(module);

    if (repModule != null) {
      ApplicationDeploymentInfo republishDeploymentInfo = repModule.getDeploymentInfo();
      if (republishDeploymentInfo != null) {
        DeploymentInfoWorkingCopy copy = appModule.resolveDeploymentInfoWorkingCopy(monitor);
        copy.setInfo(republishDeploymentInfo);
        copy.save();
      }
    }

    // Validate the existing deployment info. Do NOT save or make changes to
    // the deployment info prior to this stage
    // (for example, saving a working copy of the deployment info with
    // default values), unless it was done so for a module that is being
    // republished, as if the deployment info is valid,
    // the wizard will not open. We want the deployment wizard to ALWAYS
    // open when deploying an application for the first time (i.e the app
    // will not have
    // a deployment info set), even if we have to populate that deployment
    // info with default values or values from the manifest file. The latter
    // should only occur AFTER the handler decides to open the wizard.
    if (!appModule.validateDeploymentInfo().isOK()) {

      // Any application that can be pushed to a CF server
      // MUST have a delegate
      // which knows how to configure that application. If no
      // delegate is found,
      // the application is not currently deployable to a CF
      // server. In that case, a delegate
      // may be required to be registered for that application
      // type.
      final ApplicationWizardDelegate providerDelegate = ApplicationWizardRegistry.getWizardProvider(appModule
          .getLocalModule());

      if (providerDelegate == null) {
        throw CloudErrorUtil.toCoreException("Failed to open application deployment wizard for: " //$NON-NLS-1$
            + appModule.getDeployedApplicationName() + " when attempting to push application to " //$NON-NLS-1$
            + server.getServer().getName()
            + ". No application provider found that corresponds to the application type: " //$NON-NLS-1$
            + appModule.getLocalModule().getModuleType().getId());
      }

      // Now parse the manifest file, if it exists, and load into a
      // deployment info working copy.
      // Do NOT save the working copy yet, as a user may cancel the
      // operation from the wizard.
      // THe working copy should only be saved by the wizard if a user
      // clicks "OK".
      DeploymentInfoWorkingCopy workingCopy = null;
      try {
        workingCopy = new ManifestParser(appModule, server).load(monitor);
      }
      catch (Throwable ce) {
        // Some failure occurred reading the manifest file. Proceed
        // anyway, to allow the user to manually enter deployment
        // values.
        CloudFoundryPlugin.logError(ce);
      }

      // A working copy of the deployment descriptor is needed in order to
      // prepopulate the application deployment wizard.
      if (workingCopy == null) {
        workingCopy = appModule.resolveDeploymentInfoWorkingCopy(monitor);
      }

      // Get the old working copy in case during the deployment wizard,
      // the app name changes
      // Apps are looked up by app name in the manifest, therefore if the
      // app name changed,
      // the old entry in the manifest
      ApplicationDeploymentInfo oldInfo = workingCopy.copy();

      final boolean[] cancelled = { false };
      final boolean[] writeToManifest = { false };
      final IStatus[] status = { Status.OK_STATUS };
      final DeploymentInfoWorkingCopy finWorkingCopy = workingCopy;
View Full Code Here

      // from
      // existing deployment infos.
      // Only the actual deployed app properties (e.g. name, services,
      // URLs)
      // are updated from the cloud application
      ApplicationDeploymentInfo cloudApplicationInfo = resolveDeployedApplicationInformation();
      if (cloudApplicationInfo != null) {
        internalSetDeploymentInfo(cloudApplicationInfo);
      }
    }
  }
View Full Code Here

    if (application == null) {
      return null;
    }

    AbstractApplicationDelegate delegate = ApplicationRegistry.getApplicationDelegate(getLocalModule());
    ApplicationDeploymentInfo info = null;
    CloudFoundryServer cloudServer = getCloudFoundryServer();

    if (delegate != null) {
      info = delegate.resolveApplicationDeploymentInfo(this, cloudServer);
    }
View Full Code Here

   * also set in the module as the module's current deployment information.
   */
  protected ApplicationDeploymentInfo getDefaultDeploymentInfo(IProgressMonitor monitor) throws CoreException {

    AbstractApplicationDelegate delegate = ApplicationRegistry.getApplicationDelegate(getLocalModule());
    ApplicationDeploymentInfo defaultInfo = null;

    if (delegate != null) {
      defaultInfo = delegate.getDefaultApplicationDeploymentInfo(this, getCloudFoundryServer(), monitor);
    }

View Full Code Here

   * application type. It will have an app name as well as memory setting.
   * @return Non-null general deployment info with basic information for
   * application deployment.
   */
  protected ApplicationDeploymentInfo createGeneralDefaultInfo() {
    ApplicationDeploymentInfo info = new ApplicationDeploymentInfo(getDeployedApplicationName());
    info.setMemory(CloudUtil.DEFAULT_MEMORY);
    return info;
  }
View Full Code Here

      synchronized (appModule) {

        // Set the working copy as a regular deployment info, as to not
        // keeping
        // a reference to the working copy
        ApplicationDeploymentInfo info = new ApplicationDeploymentInfo(getDeployedApplicationName());
        info.setInfo(this);
        appModule.internalSetDeploymentInfo(info);
      }
    }
View Full Code Here

TOP

Related Classes of org.cloudfoundry.ide.eclipse.server.core.ApplicationDeploymentInfo

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.