Search in sources :

Example 1 with FileAlreadyExistsException

use of org.apache.geode.internal.process.FileAlreadyExistsException in project geode by apache.

the class ServerLauncher method start.

/**
   * Invokes the 'start' command and operation to startup a GemFire server (a cache server). Note,
   * this method will cause the JVM to block upon server start, providing the calling Thread is a
   * non-daemon Thread.
   *
   * @see #run()
   */
public ServerState start() {
    if (isStartable()) {
        INSTANCE.compareAndSet(null, this);
        try {
            process = new ControllableProcess(this.controlHandler, new File(getWorkingDirectory()), ProcessType.SERVER, isForcing());
            if (!isDisableDefaultServer()) {
                assertPortAvailable(getServerBindAddress(), getServerPort());
            }
            SystemFailure.setExitOK(true);
            ProcessLauncherContext.set(isRedirectingOutput(), getOverriddenDefaults(), new StartupStatusListener() {

                @Override
                public void setStatus(final String statusMessage) {
                    debug("Callback setStatus(String) called with message (%1$s)...", statusMessage);
                    ServerLauncher.this.statusMessage = statusMessage;
                }
            });
            try {
                final Properties gemfireProperties = getDistributedSystemProperties(getProperties());
                this.cache = createCache(gemfireProperties);
                // Set the resource manager options
                if (this.criticalHeapPercentage != null) {
                    this.cache.getResourceManager().setCriticalHeapPercentage(getCriticalHeapPercentage());
                }
                if (this.evictionHeapPercentage != null) {
                    this.cache.getResourceManager().setEvictionHeapPercentage(getEvictionHeapPercentage());
                }
                if (this.criticalOffHeapPercentage != null) {
                    this.cache.getResourceManager().setCriticalOffHeapPercentage(getCriticalOffHeapPercentage());
                }
                if (this.evictionOffHeapPercentage != null) {
                    this.cache.getResourceManager().setEvictionOffHeapPercentage(getEvictionOffHeapPercentage());
                }
                this.cache.setIsServer(true);
                startCacheServer(this.cache);
                assignBuckets(this.cache);
                rebalance(this.cache);
            } finally {
                ProcessLauncherContext.remove();
            }
            debug("Running Server on (%1$s) in (%2$s) as (%2$s)...", getId(), getWorkingDirectory(), getMember());
            this.running.set(true);
            return new ServerState(this, Status.ONLINE);
        } catch (AuthenticationRequiredException e) {
            failOnStart(e);
            throw new AuthenticationRequiredException("user/password required. Please start your server with --user and --password. " + e.getMessage());
        } catch (GemFireSecurityException e) {
            failOnStart(e);
            throw new GemFireSecurityException(e.getMessage());
        } catch (IOException e) {
            failOnStart(e);
            throw new RuntimeException(LocalizedStrings.Launcher_Command_START_IO_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId(), e.getMessage()), e);
        } catch (FileAlreadyExistsException e) {
            failOnStart(e);
            throw new RuntimeException(LocalizedStrings.Launcher_Command_START_PID_FILE_ALREADY_EXISTS_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId()), e);
        } catch (PidUnavailableException e) {
            failOnStart(e);
            throw new RuntimeException(LocalizedStrings.Launcher_Command_START_PID_UNAVAILABLE_ERROR_MESSAGE.toLocalizedString(getServiceName(), getId(), getWorkingDirectory(), e.getMessage()), e);
        } catch (ClusterConfigurationNotAvailableException e) {
            failOnStart(e);
            throw e;
        } catch (RuntimeException e) {
            failOnStart(e);
            throw e;
        } catch (Exception e) {
            failOnStart(e);
            throw new RuntimeException(e);
        } catch (Error e) {
            failOnStart(e);
            throw e;
        } finally {
            this.starting.set(false);
        }
    } else {
        throw new IllegalStateException(LocalizedStrings.Launcher_Command_START_SERVICE_ALREADY_RUNNING_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId()));
    }
}
Also used : ControllableProcess(org.apache.geode.internal.process.ControllableProcess) FileAlreadyExistsException(org.apache.geode.internal.process.FileAlreadyExistsException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) IOException(java.io.IOException) Properties(java.util.Properties) TimeoutException(java.util.concurrent.TimeoutException) PidUnavailableException(org.apache.geode.internal.process.PidUnavailableException) MBeanInvocationFailedException(org.apache.geode.internal.process.MBeanInvocationFailedException) FileAlreadyExistsException(org.apache.geode.internal.process.FileAlreadyExistsException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) FileNotFoundException(java.io.FileNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ConnectionFailedException(org.apache.geode.internal.process.ConnectionFailedException) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) OptionException(joptsimple.OptionException) UnableToControlProcessException(org.apache.geode.internal.process.UnableToControlProcessException) ClusterConfigurationNotAvailableException(org.apache.geode.internal.process.ClusterConfigurationNotAvailableException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AttachAPINotFoundException(org.apache.geode.lang.AttachAPINotFoundException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) StartupStatusListener(org.apache.geode.internal.process.StartupStatusListener) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) PidUnavailableException(org.apache.geode.internal.process.PidUnavailableException) ClusterConfigurationNotAvailableException(org.apache.geode.internal.process.ClusterConfigurationNotAvailableException) File(java.io.File)

Example 2 with FileAlreadyExistsException

use of org.apache.geode.internal.process.FileAlreadyExistsException in project geode by apache.

the class LocatorLauncher method start.

/**
   * Starts a Locator running on the specified port and bind address, as determined by getPort and
   * getBindAddress respectively, defaulting to 10334 and 'localhost' if not specified, with both
   * peer and server location enabled.
   * 
   * 'start' is an asynchronous invocation of the Locator. As such, this method makes no guarantees
   * whether the Locator's location services (peer and server) are actually running before it
   * returns. The Locator's location-based services are initiated in separate, daemon Threads and
   * depends on the relative timing and scheduling of those Threads by the JVM. If the application
   * using this API wishes for the Locator to continue running after normal application processing
   * completes, then one must call <code>waitOnLocator</code>.
   * 
   * Given the nature of start, the Locator's status will be in either 1 of 2 possible states. If
   * the 'request' to start the Locator proceeds without exception, the status will be 'STARTED'.
   * However, if any exception is encountered during the normal startup sequence, then a
   * RuntimeException is thrown and the status is set to 'STOPPED'.
   * 
   * @return a LocatorState to reflect the state of the Locator after start.
   * @throws RuntimeException if the Locator failed to start for any reason.
   * @throws IllegalStateException if the Locator is already running.
   * @see #failOnStart(Throwable)
   * @see #getBindAddress()
   * @see #getDistributedSystemProperties()
   * @see #isForcing()
   * @see #getLogFile()
   * @see #getLocatorPidFile
   * @see #getPort()
   * @see #status()
   * @see #stop()
   * @see #waitOnLocator()
   * @see #waitOnStatusResponse(long, long, java.util.concurrent.TimeUnit)
   * @see org.apache.geode.distributed.LocatorLauncher.LocatorState
   * @see org.apache.geode.distributed.AbstractLauncher.Status#NOT_RESPONDING
   * @see org.apache.geode.distributed.AbstractLauncher.Status#ONLINE
   * @see org.apache.geode.distributed.AbstractLauncher.Status#STARTING
   */
@SuppressWarnings("deprecation")
public LocatorState start() {
    if (isStartable()) {
        INSTANCE.compareAndSet(null, this);
        try {
            this.process = new ControllableProcess(this.controlHandler, new File(getWorkingDirectory()), ProcessType.LOCATOR, isForcing());
            assertPortAvailable(getBindAddress(), getPort());
            ProcessLauncherContext.set(isRedirectingOutput(), getOverriddenDefaults(), new StartupStatusListener() {

                @Override
                public void setStatus(final String statusMessage) {
                    LocatorLauncher.this.statusMessage = statusMessage;
                }
            });
            // TODO : remove the extra param for loadFromSharedConfigDir
            try {
                this.locator = InternalLocator.startLocator(getPort(), getLogFile(), null, null, null, getBindAddress(), true, getDistributedSystemProperties(), getHostnameForClients());
            } finally {
                ProcessLauncherContext.remove();
            }
            debug("Running Locator on (%1$s) in (%2$s) as (%2$s)...", getId(), getWorkingDirectory(), getMember());
            running.set(true);
            return new LocatorState(this, Status.ONLINE);
        } catch (IOException e) {
            failOnStart(e);
            throw new RuntimeException(LocalizedStrings.Launcher_Command_START_IO_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId(), e.getMessage()), e);
        } catch (FileAlreadyExistsException e) {
            failOnStart(e);
            throw new RuntimeException(LocalizedStrings.Launcher_Command_START_PID_FILE_ALREADY_EXISTS_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId()), e);
        } catch (PidUnavailableException e) {
            failOnStart(e);
            throw new RuntimeException(LocalizedStrings.Launcher_Command_START_PID_UNAVAILABLE_ERROR_MESSAGE.toLocalizedString(getServiceName(), getId(), getWorkingDirectory(), e.getMessage()), e);
        } catch (Error e) {
            failOnStart(e);
            throw e;
        } catch (RuntimeException e) {
            failOnStart(e);
            throw e;
        } catch (Exception e) {
            failOnStart(e);
            throw new RuntimeException(e);
        } finally {
            this.starting.set(false);
        }
    } else {
        throw new IllegalStateException(LocalizedStrings.Launcher_Command_START_SERVICE_ALREADY_RUNNING_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId()));
    }
}
Also used : ControllableProcess(org.apache.geode.internal.process.ControllableProcess) FileAlreadyExistsException(org.apache.geode.internal.process.FileAlreadyExistsException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) PidUnavailableException(org.apache.geode.internal.process.PidUnavailableException) MBeanInvocationFailedException(org.apache.geode.internal.process.MBeanInvocationFailedException) FileAlreadyExistsException(org.apache.geode.internal.process.FileAlreadyExistsException) FileNotFoundException(java.io.FileNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ConnectionFailedException(org.apache.geode.internal.process.ConnectionFailedException) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) OptionException(joptsimple.OptionException) UnableToControlProcessException(org.apache.geode.internal.process.UnableToControlProcessException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AttachAPINotFoundException(org.apache.geode.lang.AttachAPINotFoundException) StartupStatusListener(org.apache.geode.internal.process.StartupStatusListener) PidUnavailableException(org.apache.geode.internal.process.PidUnavailableException) File(java.io.File)

Aggregations

File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 TimeoutException (java.util.concurrent.TimeoutException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 OptionException (joptsimple.OptionException)2 ConnectionFailedException (org.apache.geode.internal.process.ConnectionFailedException)2 ControllableProcess (org.apache.geode.internal.process.ControllableProcess)2 FileAlreadyExistsException (org.apache.geode.internal.process.FileAlreadyExistsException)2 MBeanInvocationFailedException (org.apache.geode.internal.process.MBeanInvocationFailedException)2 PidUnavailableException (org.apache.geode.internal.process.PidUnavailableException)2 StartupStatusListener (org.apache.geode.internal.process.StartupStatusListener)2 UnableToControlProcessException (org.apache.geode.internal.process.UnableToControlProcessException)2 AttachAPINotFoundException (org.apache.geode.lang.AttachAPINotFoundException)2 GfJsonException (org.apache.geode.management.internal.cli.json.GfJsonException)2 ConnectException (java.net.ConnectException)1 Properties (java.util.Properties)1 ClusterConfigurationNotAvailableException (org.apache.geode.internal.process.ClusterConfigurationNotAvailableException)1 AuthenticationRequiredException (org.apache.geode.security.AuthenticationRequiredException)1