Package org.eclipse.wst.server.core.internal

Examples of org.eclipse.wst.server.core.internal.Server


    }

    @Override
    protected void performDeployment(CloudFoundryApplicationModule appModule, IProgressMonitor monitor)
        throws CoreException {
      final Server server = (Server) getServer();
      final CloudFoundryServer cloudServer = getCloudFoundryServer();
      final IModule module = modules[0];

      try {

        // Update the local cloud module representing the application
        // first.
        appModule.setErrorStatus(null);

        server.setModuleState(modules, IServer.STATE_STARTING);

        final String deploymentName = appModule.getDeploymentInfo().getDeploymentName();

        // This request does three things:
        // 1. Checks if the application external or mapped to a local
        // project. If mapped to a local project
        // it creates an archive of the application's content
        // 2. If an archive file was created, it pushes the archive
        // file.
        // 3. While pushing the archive file, a check is made to see if
        // the application exists remotely. If not, the application is
        // created in the
        // CF server.

        if (!modules[0].isExternal()) {

          printlnToConsole(appModule, Messages.CONSOLE_GENERATING_ARCHIVE);

          final ApplicationArchive applicationArchive = generateApplicationArchiveFile(
              appModule.getDeploymentInfo(), appModule, modules, server, incrementalPublish, monitor);
          File warFile = null;
          if (applicationArchive == null) {
            // Create a full war archive
            warFile = CloudUtil.createWarFile(modules, server, monitor);
            if (warFile == null || !warFile.exists()) {
              throw new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID,
                  "Unable to create war file for application: " + deploymentName)); //$NON-NLS-1$
            }

            CloudFoundryPlugin.trace("War file " + warFile.getName() + " created"); //$NON-NLS-1$ //$NON-NLS-2$
          }
          // Tell webtools the module has been published
          setModulePublishState(modules, IServer.PUBLISH_STATE_NONE);

          // update server publish status
          IModule[] serverModules = server.getModules();
          boolean allSynched = true;
          for (IModule serverModule : serverModules) {
            int modulePublishState = server.getModulePublishState(new IModule[] { serverModule });
            if (modulePublishState == IServer.PUBLISH_STATE_INCREMENTAL
                || modulePublishState == IServer.PUBLISH_STATE_FULL) {
              allSynched = false;
            }
          }

          if (allSynched) {
            server.setServerPublishState(IServer.PUBLISH_STATE_NONE);
          }

          final File warFileFin = warFile;
          final CloudFoundryApplicationModule appModuleFin = appModule;
          // Now push the application resources to the server

          new BehaviourRequest<Void>("Pushing the application " + deploymentName) { //$NON-NLS-1$
            @Override
            protected Void doRun(final CloudFoundryOperations client, SubMonitor progress)
                throws CoreException {

              pushApplication(client, appModuleFin, warFileFin, applicationArchive, progress);

              CloudFoundryPlugin.trace("Application " + deploymentName //$NON-NLS-1$
                  + " pushed to Cloud Foundry server."); //$NON-NLS-1$

              cloudServer.tagAsDeployed(module);

              return null;
            }

          }.run(monitor);

          printlnToConsole(appModule, Messages.CONSOLE_APP_PUSHED_MESSAGE);

        }

        // Verify the application exists in the server
        CloudApplication application = getDeployedCloudApplication(client,
            appModule.getDeployedApplicationName(), monitor);

        if (application == null) {
          throw CloudErrorUtil
              .toCoreException("No cloud application obtained from the Cloud Foundry server for :  " //$NON-NLS-1$
                  + appModule.getDeployedApplicationName()
                  + ". Application may not have deployed correctly to the Cloud Foundry server, or there are connection problems to the server."); //$NON-NLS-1$
        }

        // At this stage, the app is either created or it already
        // exists.
        // Set the environment variables BEFORE starting the app, and
        // BEFORE updating
        // the cloud application mapping in the module, which will
        // replace the deployment info
        updateEnvironmentVariables(appModule, monitor);

        // Update instances if it is more than 1. By default, app starts
        // with 1 instance.
        int instances = appModule.getDeploymentInfo().getInstances();
        if (instances > 1) {
          updateApplicationInstances(appModule, instances, monitor);
        }

        // If reached here it means the application creation and content
        // pushing probably succeeded without errors, therefore attempt
        // to
        // start the application
        super.performDeployment(appModule, monitor);

      }
      catch (CoreException e) {
        appModule.setErrorStatus(e);
        server.setModulePublishState(modules, IServer.PUBLISH_STATE_UNKNOWN);
        throw e;
      }
    }
View Full Code Here


     * server.core.client.CloudFoundryApplicationModule,
     * org.eclipse.core.runtime.IProgressMonitor)
     */
    protected void performDeployment(CloudFoundryApplicationModule appModule, IProgressMonitor monitor)
        throws CoreException {
      final Server server = (Server) getServer();
      final CloudFoundryApplicationModule cloudModule = appModule;

      try {
        cloudModule.setErrorStatus(null);

        final String deploymentName = cloudModule.getDeploymentInfo().getDeploymentName();

        server.setModuleState(modules, IServer.STATE_STARTING);

        if (deploymentName == null) {
          server.setModuleState(modules, IServer.STATE_STOPPED);

          throw CloudErrorUtil
              .toCoreException("Unable to start application. Missing application deployment name in application deployment information."); //$NON-NLS-1$
        }

        final ApplicationAction deploymentMode = getDeploymentConfiguration().getApplicationStartMode();
        if (deploymentMode != ApplicationAction.STOP) {
          // Start the application. Use a regular request rather than
          // a staging-aware request, as any staging errors should not
          // result in a reattempt, unlike other cases (e.g. get the
          // staging
          // logs or refreshing app instance stats after an app has
          // started).

          printlnToConsole(cloudModule, Messages.CONSOLE_PRE_STAGING_MESSAGE);

          CloudFoundryPlugin.getCallback().startApplicationConsole(getCloudFoundryServer(), cloudModule, 0,
              monitor);

          new BehaviourRequest<Void>("Starting application " + deploymentName) { //$NON-NLS-1$
            @Override
            protected Void doRun(final CloudFoundryOperations client, SubMonitor progress)
                throws CoreException {
              CloudFoundryPlugin.trace("Application " + deploymentName + " starting"); //$NON-NLS-1$ //$NON-NLS-2$

              switch (deploymentMode) {
              case DEBUG:
                // Only launch in Suspend mode
                client.debugApplication(deploymentName, DebugModeType.SUSPEND.getDebugMode());
                break;
              default:
                client.stopApplication(deploymentName);

                StartingInfo info = client.startApplication(deploymentName);
                if (info != null) {

                  cloudModule.setStartingInfo(info);

                  // Inform through callback that application
                  // has started
                  CloudFoundryPlugin.getCallback().applicationStarting(getCloudFoundryServer(),
                      cloudModule);
                }

                break;
              }
              return null;
            }
          }.run(monitor);

          // This should be staging aware, in order to reattempt on
          // staging related issues when checking if an app has
          // started or not
          new StagingAwareRequest<Void>("Waiting for application to start: }" + deploymentName) { //$NON-NLS-1$
            @Override
            protected Void doRun(final CloudFoundryOperations client, SubMonitor progress)
                throws CoreException {

              // Now verify that the application did start
              try {
                if (!waitForStart(client, deploymentName, progress)) {
                  server.setModuleState(modules, IServer.STATE_STOPPED);

                  throw new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID,
                      "Starting of " + cloudModule.getDeployedApplicationName() + " timed out")); //$NON-NLS-1$ //$NON-NLS-2$
                }
              }
              catch (InterruptedException e) {
                server.setModuleState(modules, IServer.STATE_STOPPED);
                throw new OperationCanceledException();
              }

              AbstractAppStateTracker curTracker = CloudFoundryPlugin.getAppStateTracker(getServer()
                  .getServerType().getId(), cloudModule);
              if (curTracker != null) {
                curTracker.setServer(getServer());
                curTracker.startTracking(cloudModule);
              }

              CloudFoundryPlugin.trace("Application " + deploymentName + " started"); //$NON-NLS-1$ //$NON-NLS-2$

              CloudFoundryPlugin.getCallback().applicationStarted(getCloudFoundryServer(), cloudModule);

              if (curTracker != null) {
                // Wait for application to be ready or getting
                // out of the starting state.
                boolean isAppStarting = true;
                while (isAppStarting && !progress.isCanceled()) {
                  if (curTracker.getApplicationState(cloudModule) == IServer.STATE_STARTING) {
                    try {
                      Thread.sleep(200);
                    }
                    catch (InterruptedException e) {
                      // Do nothing
                    }
                  }
                  else {
                    isAppStarting = false;
                  }
                }
                curTracker.stopTracking(cloudModule);
              }

              server.setModuleState(modules, IServer.STATE_STARTED);

              return null;
            }
          }.run(monitor);
        }
        else {
          // User has selected to deploy the app in STOP mode

          server.setModuleState(modules, IServer.STATE_STOPPED);
        }
      }
      catch (CoreException e) {
        appModule.setErrorStatus(e);
        server.setModulePublishState(modules, IServer.PUBLISH_STATE_UNKNOWN);
        throw e;
      }
    }
View Full Code Here

      this.modules = modules;
    }

    @Override
    protected void performOperation(IProgressMonitor monitor) throws CoreException {
      Server server = (Server) getServer();
      boolean succeeded = false;
      try {
        server.setModuleState(modules, IServer.STATE_STOPPING);

        CloudFoundryServer cloudServer = getCloudFoundryServer();
        final CloudFoundryApplicationModule cloudModule = cloudServer.getExistingCloudModule(modules[0]);

        if (cloudModule == null) {
          throw CloudErrorUtil.toCoreException("Unable to stop application as no cloud module found for: " //$NON-NLS-1$
              + modules[0].getName());
        }

        String stoppingApplicationMessage = NLS.bind(Messages.CONSOLE_STOPPING_APPLICATION,
            cloudModule.getDeployedApplicationName());

        clearAndPrintlnConsole(cloudModule, stoppingApplicationMessage);

        new BehaviourRequest<Void>(stoppingApplicationMessage) {
          @Override
          protected Void doRun(CloudFoundryOperations client, SubMonitor progress) throws CoreException {
            client.stopApplication(cloudModule.getDeployedApplicationName());
            return null;
          }
        }.run(monitor);

        server.setModuleState(modules, IServer.STATE_STOPPED);
        succeeded = true;

        printlnToConsole(cloudModule, Messages.CONSOLE_APP_STOPPED);
        CloudFoundryPlugin.getCallback().stopApplicationConsole(cloudModule, cloudServer);

        // If succeeded, stop all Caldecott tunnels if the app is
        // the
        // Caldecott app
        if (TunnelBehaviour.isCaldecottApp(cloudModule.getDeployedApplicationName())) {
          TunnelBehaviour handler = new TunnelBehaviour(cloudServer);
          handler.stopAndDeleteAllTunnels(monitor);
        }
      }
      finally {
        if (!succeeded) {
          server.setModuleState(modules, IServer.STATE_UNKNOWN);
        }
      }

    }
View Full Code Here

    if (cloudServer.getUsername() == null || cloudServer.getUsername().length() == 0
        || cloudServer.getPassword() == null || cloudServer.getPassword().length() == 0) {
      CloudFoundryPlugin.getCallback().getCredentials(cloudServer);
    }

    Server server = (Server) cloudServer.getServer();

    // Any Server request will require the server to be connected, so update
    // the server state
    if (server.getServerState() == IServer.STATE_STOPPED || server.getServerState() == IServer.STATE_STOPPING) {
      server.setServerState(IServer.STATE_STARTING);
    }

    try {
      T result = super.runAndWait(client, monitor);

      // No errors at this stage, therefore assume operation was completed
      // successfully, and update
      // server state accordingly
      if (server.getServerState() != IServer.STATE_STARTED) {
        server.setServerState(IServer.STATE_STARTED);
      }
      return result;

    }
    catch (CoreException ce) {
      // If the server state was starting and the error is related when
      // the operation was
      // attempted, but the operation failed
      // set the server state back to stopped.
      if (CloudErrorUtil.isConnectionError(ce) && server.getServerState() == IServer.STATE_STARTING) {
        server.setServerState(IServer.STATE_STOPPED);
      }
      // server.setServerPublishState(IServer.PUBLISH_STATE_NONE);
      throw ce;
    }
View Full Code Here

          }
        }
      }
    }
    else if (element instanceof Server) {
      Server server = (Server) element;
      if (CloudServerUtil.isCloudFoundryServer(server)) {
        CloudFoundryServer cfServer = getCloudFoundryServer(server);
        if (cfServer != null && cfServer.getUsername() != null) {
          // decoration.addSuffix(NLS.bind("  [{0}, {1}]",
          // cfServer.getUsername(), cfServer.getUrl()));
View Full Code Here

        client.login();
        return null;
      }
    }.run(monitor);

    Server server = (Server) cloudServer.getServerOriginal();
    server.setServerState(IServer.STATE_STARTED);
    server.setServerPublishState(IServer.PUBLISH_STATE_NONE);

    getApplicationUrlLookup().refreshDomains(monitor);

    refreshModules(monitor);
  }
View Full Code Here

   * @throws CoreException
   */
  public void disconnect(IProgressMonitor monitor) throws CoreException {
    CloudFoundryPlugin.getCallback().disconnecting(getCloudFoundryServer());

    Server server = (Server) getServer();
    server.setServerState(IServer.STATE_STOPPING);

    getRefreshHandler().stop();
    CloudFoundryServer cloudServer = getCloudFoundryServer();

    Collection<CloudFoundryApplicationModule> cloudModules = cloudServer.getExistingCloudModules();

    for (CloudFoundryApplicationModule appModule : cloudModules) {
      CloudFoundryPlugin.getCallback().stopApplicationConsole(appModule, cloudServer);
    }

    Set<CloudFoundryApplicationModule> deletedModules = new HashSet<CloudFoundryApplicationModule>(cloudModules);

    cloudServer.clearApplications();

    // update state for cloud applications
    server.setExternalModules(new IModule[0]);
    for (CloudFoundryApplicationModule module : deletedModules) {
      server.setModuleState(new IModule[] { module.getLocalModule() }, IServer.STATE_UNKNOWN);
    }

    server.setServerState(IServer.STATE_STOPPED);
    server.setServerPublishState(IServer.PUBLISH_STATE_NONE);
    closeCaldecottTunnels(monitor);
  }
View Full Code Here

  /**
   * This method is API used by CloudFoundry Code.
   */
  public CloudFoundryServer getCloudFoundryServer() throws CoreException {
    Server server = (Server) getServer();

    CloudFoundryServer cloudFoundryServer = (CloudFoundryServer) server.loadAdapter(CloudFoundryServer.class, null);
    if (cloudFoundryServer == null) {
      throw new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID, "Fail to load server")); //$NON-NLS-1$
    }
    return cloudFoundryServer;
  }
View Full Code Here

   * will be removed.
   * @param deployedApplications
   * @throws CoreException
   */
  public void updateModules(Map<String, CloudApplication> deployedApplications) throws CoreException {
    Server server = (Server) getServer();

    final Set<CloudFoundryApplicationModule> allModules = new HashSet<CloudFoundryApplicationModule>();
    List<CloudFoundryApplicationModule> externalModules = new ArrayList<CloudFoundryApplicationModule>();
    final Set<IModule> deletedModules = new HashSet<IModule>();

    synchronized (this) {
      // Iterate through the local WST modules, and update them based on
      // which are external (have no accessible workspace resources),
      // which
      // have no corresponding deployed application .
      // Note that some IModules may also be in the process of being
      // deleted. DO NOT recreate cloud application modules for these
      // CHANGE
      for (IModule module : server.getModules()) {
        // Find the corresponding Cloud Foundry application module for
        // the given WST server IModule
        CloudFoundryApplicationModule cloudModule = getCloudModule(module);

        if (cloudModule == null) {
          CloudFoundryPlugin.logError("Unable to find local Cloud Foundry application module for : " //$NON-NLS-1$
              + module.getName()
              + ". Try refreshing applications or disconnecting and reconnecting to the server."); //$NON-NLS-1$
          continue;
        }

        // Now process the deployed application, and re-categorise it if
        // necessary (i.e. whether it's external or not)
        CloudApplication actualApplication = deployedApplications.remove(cloudModule
            .getDeployedApplicationName());

        // Update the cloud module mapping to the cloud application,
        // such that the cloud module
        // has the latest cloud application reference.
        cloudModule.setCloudApplication(actualApplication);

        // the modules maps to an existing application
        if (actualApplication != null) {
          if (cloudModule.isExternal()) {
            externalModules.add(cloudModule);
          }
          allModules.add(cloudModule);
        }
        else if (getData() != null && getData().isUndeployed(module)) {
          // deployment is still in progress
          allModules.add(cloudModule);
        }
        else {
          // the module maps to an application that no longer exists
          deletedModules.add(module);
        }
      }

      // create modules for new applications
      if (getData() != null) {
        for (CloudApplication application : deployedApplications.values()) {
          CloudFoundryApplicationModule appModule = getData().createModule(application);
          externalModules.add(appModule);
          allModules.add(appModule);
        }
      }

      // update state for cloud applications
      server.setExternalModules(externalModules.toArray(new IModule[0]));

      for (IModule module : server.getModules()) {
        CloudFoundryApplicationModule appModule = getExistingCloudModule(module);
        if (appModule != null) {
          updateState(server, appModule);
        }
      }

      // FIXNS: This seems to trigger an infinite "recursion", since
      // deleteModules(..) delegates to the server behaviour, which then
      // attempts to delete modules in a server instance that is not saved
      // and when server behaviour delete operation is complete, it will
      // trigger a refresh operation which then proceeds to update
      // modules, but since WST still indicates that the module has not
      // been deleted
      // deleteModule size will not be empty, which will again invoke the
      // server behaviour...
      // update state for deleted applications to trigger a refresh
      if (deletedModules.size() > 0) {
        for (IModule module : deletedModules) {
          server.setModuleState(new IModule[] { module }, IServer.STATE_UNKNOWN);
        }
        deleteModules(deletedModules);
      }

      if (getData() != null) {
View Full Code Here

    boolean isPublishOverlaysEnabled = isPublishOverlaysEnabled();
    for(Map.Entry<IServer, List<IModule>> entries : republishableServers.entrySet()) {
      IServer iserver = entries.getKey();
      boolean shouldPublish = isPublishOverlaysEnabled;
      if (iserver instanceof Server) {
        Server server = ((Server)iserver);
        List<IModule> modules = entries.getValue();
        IModule[] mod = new IModule[modules.size()];
        modules.toArray(mod);
        server.setModulePublishState(mod, IServer.PUBLISH_STATE_INCREMENTAL);
        int autoPublishSetting = server.getAutoPublishSetting();
        shouldPublish = shouldPublish && (autoPublishSetting == Server.AUTO_PUBLISH_RESOURCE ||
                            (autoPublishSetting == Server.AUTO_PUBLISH_BUILD && buildOccurred));
      }
      if (shouldPublish && iserver.getServerState() == IServer.STATE_STARTED) {
        iserver.publish(IServer.PUBLISH_INCREMENTAL, new NullProgressMonitor());
View Full Code Here

TOP

Related Classes of org.eclipse.wst.server.core.internal.Server

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.