OperationAPI

Methods

startMicroservices

Starts microservices on provided node.

MicroservicesOperationResult startMicroservices(
        final NodeConnectionData node, final String[] microservicesNames
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microservicesNames - Names of microservices for command.

Result:

Result of operations - exceptions are returned on errors (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

startMicroservice

Starts microservice on provided node.

MicroserviceOperationResult startMicroservice(
        final NodeConnectionData node, final String microserviceName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

startAndActivateMicroservices

Starts and activates microservices on provided node.

MicroservicesOperationResult startAndActivateMicroservices(
        final NodeConnectionData node, final String[] microservicesNames
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microservicesNames - Names of microservices for command.

Result:

Result of operations - exceptions are returned on errors (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

startAndActivateMicroservice

Starts and activates microservice on provided node.

MicroserviceOperationResult startAndActivateMicroservice(
        final NodeConnectionData node, final String microserviceName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

restartMicroservices

Restarts microservices on provided node.

MicroservicesOperationResult restartMicroservices(
        final NodeConnectionData node, final String[] microservicesNames
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microservicesNames - Names of microservices for command.

Result:

Result of operations - exceptions are returned on errors (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

restartMicroservice

Restart microservice on provided node.

MicroserviceOperationResult restartMicroservice(
        final NodeConnectionData node, final String microserviceName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

stopMicroservices

Stops microservices on provided node.

MicroservicesOperationResult stopMicroservices(
        final NodeConnectionData node, final String[] microservicesNames
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microservicesNames - Names of microservices for command.

Result:

Result of operations - exceptions are returned on errors (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

stopMicroservice

Stops microservice on provided node.

MicroserviceOperationResult stopMicroservice(
        final NodeConnectionData node, final String microserviceName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

terminateMicroservices

Stops forcely microservices on provided node.

MicroservicesOperationResult terminateMicroservices(
        final NodeConnectionData node, final String[] microservicesNames
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microservicesNames - Names of microservices for command.

Result:

Result of operations - exceptions are returned on errors (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

terminateMicroservice

Stops forcely microservice on provided node.

MicroserviceOperationResult terminateMicroservice(
        final NodeConnectionData node, final String microserviceName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

removeMicroservices

Removes microservices on provided node.

MicroservicesOperationResult removeMicroservices(
        final NodeConnectionData node, final String[] microservicesNames
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microservicesNames - Names of microservices for command.

Result:

Result of operations - exceptions are returned on errors (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

removeMicroservice

Remove microservice on provided node.

MicroserviceOperationResult removeMicroservice(
        final NodeConnectionData node, final String microserviceName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

activateMicroservices

Activates microservices on provided node.

MicroservicesOperationResult activateMicroservices(
        final NodeConnectionData node, final String[] microservicesNames
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microservicesNames - Names of microservices for command.

Result:

Result of operations - exceptions are returned on errors (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

activateMicroservice

Activate microservice on provided node.

MicroserviceOperationResult activateMicroservice(
        final NodeConnectionData node, final String microserviceName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

deactivateMicroservices

Deactivates microservices on provided node.

MicroservicesOperationResult deactivateMicroservices(
        final NodeConnectionData node, final String[] microservicesNames
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microservicesNames - Names of microservices for command.

Result:

Result of operations - exceptions are returned on errors (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

deactivateMicroservice

Deactivate microservice on provided node.

MicroserviceOperationResult deactivateMicroservice(
        final NodeConnectionData node, final String microserviceName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

uploadMicroservice

Uploads microservice on provided node.

MicroserviceOperationResult uploadMicroservice(
        final NodeConnectionData node, final String microserviceName, final File file
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • microserviceName - Name of microservice for command.
  • file - File pointing into microservice's zip.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

executeTechnicalMicroserviceCommand

Executes selected command on technical microservice on provided node.

TechnicalMicroserviceOperationResult executeTechnicalMicroserviceCommand(
        final NodeConnectionData node, final String technicalMicroserviceName, final String commandName
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.
  • technicalMicroserviceName - Name ot technical microservice to execute command on.
  • commandName - Name of command to execute.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

releaseAllLocks

Releases all locks on node.

NodeOperationResult releaseAllLocks(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

activateMainServer

Activates node.

NodeOperationResult activateMainServer(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

deactivateMainServer

Deactivates node.

NodeOperationResult deactivateMainServer(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

activateForclyMainServer

Activates node forcely.

NodeOperationResult activateForclyMainServer(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

deactivateForclyMainServer

Deactivates node forcely.

NodeOperationResult deactivateForclyMainServer(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

stopMainServer

Stops main server.

NodeOperationResult stopMainServer(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

terminateMainServer

Stops forcely main server.

NodeOperationResult terminateMainServer(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

terminateMainServerWithoutCheckingState

Stops forcely main server without checking internal state.

NodeOperationResult terminateMainServerWithoutCheckingState(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is throw when thread was interrupted during execution.

makeAvailableAllLocalMicroservices

Makes all microservices on node available.

NodeOperationResult makeAvailableAllLocalMicroservices(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

makeUnavailableAllLocalMicroservices

Makes all microservices on node unavailable.

NodeOperationResult makeUnavailableAllLocalMicroservices(
        final NodeConnectionData node
) throws ExecutionInterruptedException;

Arguments:

  • node - Node to execute command.

Result:

Result of operation - exception is returned on error (instead of being thrown).

Exceptions:

  • ExecutionInterruptedException - Is thrown when thread was interrupted during execution.

Common objects

MicroserviceOperationResult

There are three scenarios for operation. First is that is was executed correctly. You can check if this happened by executing method isExecutedCorrectly(). If there were problems with execution there are now two options. There was problem with connecting to server (you can check this by calling method getMainServerNotConnectedException() and checking if result is not null) or there was problem with execution (you can check this by calling method getExecutionException() and checking if result is not null). There is also method throwExceptionIfAny() for your convinience, if you want to throws errors. You may ask why errors are not thrown by method itself. It's due to fact that some methods are executed for multiple objects and for one of them there could be an error, while other ones were executed correctly. To make execution of every method similar (for simplicity of handling it) even methods executed only for one object does not throw errors.

MicroservicesOperationResult

This result is grouping results for each microservice passed as input for operation. Result is a map where microservices' names are the keys while operation results are the values. You can access this map by method getResults(). Operation results are of type MicroserviceOperationResult.

TechnicalMicroserviceOperationResult

There are three scenarios for operation. First is that is was executed correctly. You can check if this happened by executing method isExecutedCorrectly(). If there were problems with execution there are now two options. There was problem with connecting to server (you can check this by calling method getMainServerNotConnectedException() and checking if result is not null) or there was problem with execution (you can check this by calling method getExecutionException() and checking if result is not null). There is also method throwExceptionIfAny() for your convinience, if you want to throws errors. You may ask why errors are not thrown by method itself. It's due to fact that some methods are executed for multiple objects and for one of them there could be an error, while other ones were executed correctly. To make execution of every method similar (for simplicity of handling it) even methods executed only for one object does not throw errors.

TechnicalMicroservicesOperationResult

This result is grouping results for each technical microservice passed as input for operation. Result is a map where technical microservices' names are the keys while operation results are the values. You can access this map by method getResults(). Operation results are of type TechnicalMicroserviceOperationResult.

NodeOperationResult

There are three scenarios for operation. First is that is was executed correctly. You can check if this happened by executing method isExecutedCorrectly(). If there were problems with execution there are now two options. There was problem with connecting to server (you can check this by calling method getMainServerNotConnectedException() and checking if result is not null) or there was problem with execution (you can check this by calling method getExecutionException() and checking if result is not null). There is also method throwExceptionIfAny() for your convinience, if you want to throws errors. You may ask why errors are not thrown by method itself. It's due to fact that some methods are executed for multiple objects and for one of them there could be an error, while other ones were executed correctly. To make execution of every method similar (for simplicity of handling it) even methods executed only for one object does not throw errors.

Example

starting microservice

Full example of starting microservice.

import com.jlupin.entrypoint.command.forwarder.transmission.main.JLupinMainServerTransmissionEntryPointCommandForwarder;
import com.jlupin.impl.util.communication.factory.socket.impl.defaults.JLupinDefaultCommunicationProtocolUtilSocketFactoryImpl;
import com.jlupin.platform.management.client.api.operation.impl.OperationAPIImpl;
import com.jlupin.platform.management.client.api.operation.interfaces.OperationAPI;
import com.jlupin.platform.management.client.api.operation.pojo.MicroserviceOperationResult;
import com.jlupin.platform.management.client.common.pojo.NodeConnectionData;
import com.jlupin.platform.management.client.common.pojo.exceptions.ExecutionInterruptedException;
import com.jlupin.platform.management.client.remote.executor.cache.impl.InMemoryRemoteExecutorCacheImpl;
import com.jlupin.platform.management.client.remote.executor.cache.intefaces.RemoteExecutorCache;
import com.jlupin.platform.management.client.remote.executor.impl.RemoteExecutorWithCacheImpl;
import com.jlupin.platform.management.client.remote.executor.interfaces.RemoteExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example {
    private static final Logger logger = LoggerFactory.getLogger(Example.class);

    public void example() {
        final SSLSocketFactory sslSocketFactory = JLupinSecurityUtil.getTwoWayAuthenticationSSLClientSocketFactory(
                "ssl/client/clientX509Certificate.crt",
                "ssl/client/clientPrivateKey.pk",
                "ssl/server/serverX509Certificate.crt"
        );

        JLupinSSLCommunicationProtocolUtilSocketFactoryImpl.initialize(sslSocketFactory);

        final JLupinMainServerTransmissionEntryPointCommandForwarder commandForwarder =
                new JLupinMainServerTransmissionEntryPointCommandForwarder(
                        JLupinSSLCommunicationProtocolUtilSocketFactoryImpl.getInstance()
                );

        final RemoteExecutorCache cache = new InMemoryRemoteExecutorCacheImpl();

        final RemoteExecutor remoteExecutor = new RemoteExecutorWithCacheImpl(
                logger, logger::debug, "client-name", commandForwarder, cache
        );

        final OperationAPI operationAPI = new OperationAPIImpl(remoteExecutor);

        final NodeConnectionData nodeConnectionData = new NodeConnectionData(); // defaults to 127.0.0.1:9096

        final MicroserviceOperationResult result;
        try {
            result = operationAPI.startMicroservice(nodeConnectionData, "nativeMicroservice");
        } catch (ExecutionInterruptedException e) {
            e.printStackTrace();
            return;
        }

        if (result.isExecutedCorrectly()) {
            System.out.println("Microservice nativeMicroservice was started.");
            return;
        }

        System.out.println("There were error while starting nativeMicroservice.");

        if (result.getMainServerNotConnectedException() != null) {
            result.getMainServerNotConnectedException().printStackTrace();
            return;
        }

        if (result.getExecutionException() != null) {
            result.getExecutionException().printStackTrace();
            return;
        }
    }
}

stopping multiple microservices

Full example of stopping multiple microservices.

import com.jlupin.entrypoint.command.forwarder.transmission.main.JLupinMainServerTransmissionEntryPointCommandForwarder;
import com.jlupin.impl.util.communication.factory.socket.impl.defaults.JLupinDefaultCommunicationProtocolUtilSocketFactoryImpl;
import com.jlupin.platform.management.client.api.operation.impl.OperationAPIImpl;
import com.jlupin.platform.management.client.api.operation.interfaces.OperationAPI;
import com.jlupin.platform.management.client.api.operation.pojo.MicroserviceOperationResult;
import com.jlupin.platform.management.client.api.operation.pojo.MicroservicesOperationResult;
import com.jlupin.platform.management.client.common.pojo.NodeConnectionData;
import com.jlupin.platform.management.client.common.pojo.exceptions.ExecutionInterruptedException;
import com.jlupin.platform.management.client.remote.executor.cache.impl.InMemoryRemoteExecutorCacheImpl;
import com.jlupin.platform.management.client.remote.executor.cache.intefaces.RemoteExecutorCache;
import com.jlupin.platform.management.client.remote.executor.impl.RemoteExecutorWithCacheImpl;
import com.jlupin.platform.management.client.remote.executor.interfaces.RemoteExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class Example {
    private static final Logger logger = LoggerFactory.getLogger(Example.class);

    public void example() {
        final SSLSocketFactory sslSocketFactory = JLupinSecurityUtil.getTwoWayAuthenticationSSLClientSocketFactory(
                "ssl/client/clientX509Certificate.crt",
                "ssl/client/clientPrivateKey.pk",
                "ssl/server/serverX509Certificate.crt"
        );

        JLupinSSLCommunicationProtocolUtilSocketFactoryImpl.initialize(sslSocketFactory);

        final JLupinMainServerTransmissionEntryPointCommandForwarder commandForwarder =
                new JLupinMainServerTransmissionEntryPointCommandForwarder(
                        JLupinSSLCommunicationProtocolUtilSocketFactoryImpl.getInstance()
                );

        final RemoteExecutorCache cache = new InMemoryRemoteExecutorCacheImpl();

        final RemoteExecutor remoteExecutor = new RemoteExecutorWithCacheImpl(
                logger, logger::debug, "client-name", commandForwarder, cache
        );

        final OperationAPI operationAPI = new OperationAPIImpl(remoteExecutor);

        final NodeConnectionData nodeConnectionData = new NodeConnectionData(); // defaults to 127.0.0.1:9096

        final MicroservicesOperationResult results;
        try {
            results = operationAPI.stopMicroservices(nodeConnectionData, new String[] { "nativeMicroservice", "servletMicroservice" });
        } catch (ExecutionInterruptedException e) {
            e.printStackTrace();
            return;
        }

        final Map<String, MicroserviceOperationResult> resultsMap = results.getResults();
        for (final Map.Entry<String, MicroserviceOperationResult> entry : resultsMap.entrySet()) {
            final String microserviceName = entry.getKey();
            final MicroserviceOperationResult result = entry.getValue();

            if (result.isExecutedCorrectly()) {
                System.out.println("Microservice " + microserviceName + " was started.");
                continue;
            }

            System.out.println("There were error while starting " + microserviceName + ".");

            if (result.getMainServerNotConnectedException() != null) {
                result.getMainServerNotConnectedException().printStackTrace();
                continue;
            }

            if (result.getExecutionException() != null) {
                result.getExecutionException().printStackTrace();
                continue;
            }
        }
    }
}