Search in sources :

Example 1 with PidUnavailableException

use of org.apache.geode.internal.process.PidUnavailableException 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 PidUnavailableException

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

the class LocatorLauncher method stopWithWorkingDirectory.

private LocatorState stopWithWorkingDirectory() {
    int parsedPid = 0;
    try {
        final ProcessController controller = new ProcessControllerFactory().createProcessController(this.controllerParameters, new File(getWorkingDirectory()), ProcessType.LOCATOR.getPidFileName(), READ_PID_FILE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        parsedPid = controller.getProcessId();
        // NOTE in-process request will go infinite loop unless we do the following
        if (parsedPid == ProcessUtils.identifyPid()) {
            final LocatorLauncher runningLauncher = getInstance();
            if (runningLauncher != null) {
                return runningLauncher.stopInProcess();
            }
        }
        controller.stop();
        return new LocatorState(this, Status.STOPPED);
    } catch (ConnectionFailedException e) {
        // failed to attach to locator JVM
        return createNoResponseState(e, "Failed to connect to locator with process id " + parsedPid);
    } catch (FileNotFoundException e) {
        // could not find pid file
        return createNoResponseState(e, "Failed to find process file " + ProcessType.LOCATOR.getPidFileName() + " in " + getWorkingDirectory());
    } catch (IOException e) {
        // failed to open or read file or dir
        return createNoResponseState(e, "Failed to communicate with locator with process id " + parsedPid);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return createNoResponseState(e, "Interrupted while trying to communicate with locator with process id " + parsedPid);
    } catch (MBeanInvocationFailedException e) {
        // MBean either doesn't exist or method or attribute don't exist
        return createNoResponseState(e, "Failed to communicate with locator with process id " + parsedPid);
    } catch (PidUnavailableException e) {
        // couldn't determine pid from within locator JVM
        return createNoResponseState(e, "Failed to find usable process id within file " + ProcessType.LOCATOR.getPidFileName() + " in " + getWorkingDirectory());
    } catch (TimeoutException e) {
        return createNoResponseState(e, "Timed out trying to find usable process id within file " + ProcessType.LOCATOR.getPidFileName() + " in " + getWorkingDirectory());
    } catch (UnableToControlProcessException e) {
        return createNoResponseState(e, "Failed to communicate with locator with process id " + parsedPid);
    }
}
Also used : ProcessControllerFactory(org.apache.geode.internal.process.ProcessControllerFactory) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) UnableToControlProcessException(org.apache.geode.internal.process.UnableToControlProcessException) ProcessController(org.apache.geode.internal.process.ProcessController) MBeanInvocationFailedException(org.apache.geode.internal.process.MBeanInvocationFailedException) PidUnavailableException(org.apache.geode.internal.process.PidUnavailableException) File(java.io.File) ConnectionFailedException(org.apache.geode.internal.process.ConnectionFailedException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with PidUnavailableException

use of org.apache.geode.internal.process.PidUnavailableException 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)

Example 4 with PidUnavailableException

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

the class ServerLauncher method statusWithWorkingDirectory.

private ServerState statusWithWorkingDirectory() {
    int parsedPid = 0;
    try {
        final ProcessController controller = new ProcessControllerFactory().createProcessController(this.controllerParameters, new File(getWorkingDirectory()), ProcessType.SERVER.getPidFileName(), READ_PID_FILE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        parsedPid = controller.getProcessId();
        // note: in-process request will go infinite loop unless we do the following
        if (parsedPid == identifyPid()) {
            final ServerLauncher runningLauncher = getInstance();
            if (runningLauncher != null) {
                return runningLauncher.statusInProcess();
            }
        }
        final String statusJson = controller.status();
        return ServerState.fromJson(statusJson);
    } catch (ConnectionFailedException e) {
        // failed to attach to server JVM
        return createNoResponseState(e, "Failed to connect to server with process id " + parsedPid);
    } catch (FileNotFoundException e) {
        // could not find pid file
        return createNoResponseState(e, "Failed to find process file " + ProcessType.SERVER.getPidFileName() + " in " + getWorkingDirectory());
    } catch (IOException e) {
        // failed to open or read file or dir
        return createNoResponseState(e, "Failed to communicate with server with process id " + parsedPid);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return createNoResponseState(e, "Interrupted while trying to communicate with server with process id " + parsedPid);
    } catch (MBeanInvocationFailedException e) {
        // MBean either doesn't exist or method or attribute don't exist
        return createNoResponseState(e, "Failed to communicate with server with process id " + parsedPid);
    } catch (PidUnavailableException e) {
        // couldn't determine pid from within server JVM
        return createNoResponseState(e, "Failed to find usable process id within file " + ProcessType.SERVER.getPidFileName() + " in " + getWorkingDirectory());
    } catch (UnableToControlProcessException e) {
        return createNoResponseState(e, "Failed to communicate with server with process id " + parsedPid);
    } catch (TimeoutException e) {
        return createNoResponseState(e, "Failed to communicate with server with process id " + parsedPid);
    }
}
Also used : ProcessControllerFactory(org.apache.geode.internal.process.ProcessControllerFactory) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) CacheServerLauncher(org.apache.geode.internal.cache.CacheServerLauncher) UnableToControlProcessException(org.apache.geode.internal.process.UnableToControlProcessException) ProcessController(org.apache.geode.internal.process.ProcessController) MBeanInvocationFailedException(org.apache.geode.internal.process.MBeanInvocationFailedException) PidUnavailableException(org.apache.geode.internal.process.PidUnavailableException) File(java.io.File) ConnectionFailedException(org.apache.geode.internal.process.ConnectionFailedException) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with PidUnavailableException

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

the class ServerLauncher method stopWithWorkingDirectory.

private ServerState stopWithWorkingDirectory() {
    int parsedPid = 0;
    try {
        final ProcessController controller = new ProcessControllerFactory().createProcessController(this.controllerParameters, new File(getWorkingDirectory()), ProcessType.SERVER.getPidFileName(), READ_PID_FILE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        parsedPid = controller.getProcessId();
        // NOTE in-process request will go infinite loop unless we do the following
        if (parsedPid == identifyPid()) {
            final ServerLauncher runningLauncher = getInstance();
            if (runningLauncher != null) {
                return runningLauncher.stopInProcess();
            }
        }
        controller.stop();
        return new ServerState(this, Status.STOPPED);
    } catch (ConnectionFailedException e) {
        // failed to attach to server JVM
        return createNoResponseState(e, "Failed to connect to server with process id " + parsedPid);
    } catch (FileNotFoundException e) {
        // could not find pid file
        return createNoResponseState(e, "Failed to find process file " + ProcessType.SERVER.getPidFileName() + " in " + getWorkingDirectory());
    } catch (IOException e) {
        // failed to open or read file or dir
        return createNoResponseState(e, "Failed to communicate with server with process id " + parsedPid);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return createNoResponseState(e, "Interrupted while trying to communicate with server with process id " + parsedPid);
    } catch (MBeanInvocationFailedException e) {
        // MBean either doesn't exist or method or attribute don't exist
        return createNoResponseState(e, "Failed to communicate with server with process id " + parsedPid);
    } catch (PidUnavailableException e) {
        // couldn't determine pid from within server JVM
        return createNoResponseState(e, "Failed to find usable process id within file " + ProcessType.SERVER.getPidFileName() + " in " + getWorkingDirectory());
    } catch (TimeoutException e) {
        return createNoResponseState(e, "Timed out trying to find usable process id within file " + ProcessType.SERVER.getPidFileName() + " in " + getWorkingDirectory());
    } catch (UnableToControlProcessException e) {
        return createNoResponseState(e, "Failed to communicate with server with process id " + parsedPid);
    }
}
Also used : ProcessControllerFactory(org.apache.geode.internal.process.ProcessControllerFactory) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) CacheServerLauncher(org.apache.geode.internal.cache.CacheServerLauncher) UnableToControlProcessException(org.apache.geode.internal.process.UnableToControlProcessException) ProcessController(org.apache.geode.internal.process.ProcessController) MBeanInvocationFailedException(org.apache.geode.internal.process.MBeanInvocationFailedException) PidUnavailableException(org.apache.geode.internal.process.PidUnavailableException) File(java.io.File) ConnectionFailedException(org.apache.geode.internal.process.ConnectionFailedException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 TimeoutException (java.util.concurrent.TimeoutException)6 ConnectionFailedException (org.apache.geode.internal.process.ConnectionFailedException)6 MBeanInvocationFailedException (org.apache.geode.internal.process.MBeanInvocationFailedException)6 PidUnavailableException (org.apache.geode.internal.process.PidUnavailableException)6 UnableToControlProcessException (org.apache.geode.internal.process.UnableToControlProcessException)6 ProcessController (org.apache.geode.internal.process.ProcessController)4 ProcessControllerFactory (org.apache.geode.internal.process.ProcessControllerFactory)4 UnknownHostException (java.net.UnknownHostException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 OptionException (joptsimple.OptionException)2 CacheServerLauncher (org.apache.geode.internal.cache.CacheServerLauncher)2 ControllableProcess (org.apache.geode.internal.process.ControllableProcess)2 FileAlreadyExistsException (org.apache.geode.internal.process.FileAlreadyExistsException)2 StartupStatusListener (org.apache.geode.internal.process.StartupStatusListener)2 AttachAPINotFoundException (org.apache.geode.lang.AttachAPINotFoundException)2 GfJsonException (org.apache.geode.management.internal.cli.json.GfJsonException)2 ConnectException (java.net.ConnectException)1