Search in sources :

Example 1 with DeployedArtifacts

use of com.oracle.bedrock.runtime.remote.DeployedArtifacts in project oracle-bedrock by coherence-community.

the class CurlHttpDeployerTest method shouldDeployEmptyArtifacts.

@Test
public void shouldDeployEmptyArtifacts() throws Exception {
    Map<String, DeploymentArtifact> artifacts = new HashMap<>();
    String destination = "/foo";
    Platform platform = mock(Platform.class);
    InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 1234);
    OptionsByType optionsByType = OptionsByType.empty();
    CurlHttpDeployer deploymentMethod = new CurlHttpDeployer();
    DeployedArtifacts deployedArtifacts = new DeployedArtifacts();
    deploymentMethod.deployAllArtifacts(artifacts, destination, platform, address, optionsByType, deployedArtifacts);
    verifyNoMoreInteractions(platform);
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) Platform(com.oracle.bedrock.runtime.Platform) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) DeployedArtifacts(com.oracle.bedrock.runtime.remote.DeployedArtifacts) DeploymentArtifact(com.oracle.bedrock.runtime.remote.DeploymentArtifact) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 2 with DeployedArtifacts

use of com.oracle.bedrock.runtime.remote.DeployedArtifacts in project oracle-bedrock by coherence-community.

the class CurlHttpDeployerTest method shouldDeployNullArtifacts.

@Test
public void shouldDeployNullArtifacts() throws Exception {
    String destination = "/foo";
    Platform platform = mock(Platform.class);
    InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 1234);
    OptionsByType optionsByType = OptionsByType.empty();
    CurlHttpDeployer deploymentMethod = new CurlHttpDeployer();
    DeployedArtifacts deployedArtifacts = new DeployedArtifacts();
    deploymentMethod.deployAllArtifacts(null, destination, platform, address, optionsByType, deployedArtifacts);
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) Platform(com.oracle.bedrock.runtime.Platform) InetSocketAddress(java.net.InetSocketAddress) DeployedArtifacts(com.oracle.bedrock.runtime.remote.DeployedArtifacts) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 3 with DeployedArtifacts

use of com.oracle.bedrock.runtime.remote.DeployedArtifacts in project oracle-bedrock by coherence-community.

the class WGetHttpDeployerTest method shouldDeployNullArtifacts.

@Test
public void shouldDeployNullArtifacts() throws Exception {
    String destination = "/foo";
    Platform platform = mock(Platform.class);
    InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 1234);
    OptionsByType optionsByType = OptionsByType.empty();
    WGetHttpDeployer deploymentMethod = new WGetHttpDeployer();
    DeployedArtifacts deployedArtifacts = new DeployedArtifacts();
    deploymentMethod.deployAllArtifacts(null, destination, platform, address, optionsByType, deployedArtifacts);
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) Platform(com.oracle.bedrock.runtime.Platform) InetSocketAddress(java.net.InetSocketAddress) DeployedArtifacts(com.oracle.bedrock.runtime.remote.DeployedArtifacts) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 4 with DeployedArtifacts

use of com.oracle.bedrock.runtime.remote.DeployedArtifacts in project oracle-bedrock by coherence-community.

the class HttpDeployer method deploy.

@Override
public DeployedArtifacts deploy(List<DeploymentArtifact> artifactsToDeploy, String remoteDirectory, Platform platform, Option... deploymentOptions) {
    DeployedArtifacts deployedArtifacts = new DeployedArtifacts();
    if (artifactsToDeploy == null || artifactsToDeploy.isEmpty()) {
        return deployedArtifacts;
    }
    OptionsByType optionsByType = OptionsByType.empty();
    optionsByType.addAll(platform.getOptions());
    optionsByType.addAll(deploymentOptions);
    Map<String, DeploymentArtifact> artifactMap = new LinkedHashMap<>();
    ExecutorService executor = createExecutor();
    HttpServer server = null;
    try {
        for (DeploymentArtifact artifact : artifactsToDeploy) {
            artifactMap.put("/" + UUID.randomUUID().toString(), artifact);
        }
        server = createServer(executor, artifactMap);
        deployAllArtifacts(artifactMap, remoteDirectory, platform, server.getAddress(), optionsByType, deployedArtifacts);
    } finally {
        if (server != null) {
            server.stop(0);
        }
        if (executor != null) {
            executor.shutdownNow();
        }
    }
    return deployedArtifacts;
}
Also used : DeployedArtifacts(com.oracle.bedrock.runtime.remote.DeployedArtifacts) ExecutorService(java.util.concurrent.ExecutorService) HttpServer(com.sun.net.httpserver.HttpServer) OptionsByType(com.oracle.bedrock.OptionsByType) DeploymentArtifact(com.oracle.bedrock.runtime.remote.DeploymentArtifact) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with DeployedArtifacts

use of com.oracle.bedrock.runtime.remote.DeployedArtifacts in project oracle-bedrock by coherence-community.

the class SftpDeployer method undeploy.

@Override
public DeployedArtifacts undeploy(DeployedArtifacts deployedArtifacts, Platform platform, Option... deploymentOptions) {
    DeployedArtifacts failedArtifacts = new DeployedArtifacts();
    if (!(platform instanceof RemotePlatform)) {
        throw new IllegalArgumentException("The platform parameter must be an instance of RemotePlatform");
    }
    JSchSocketFactory socketFactory = new JSchSocketFactory();
    RemotePlatform remotePlatform = (RemotePlatform) platform;
    String userName = remotePlatform.getUserName();
    Authentication authentication = remotePlatform.getAuthentication();
    String hostName = remotePlatform.getAddress().getHostName();
    int port = remotePlatform.getPort();
    // create the deployment options
    OptionsByType optionsByType = OptionsByType.empty();
    // add the Platform options
    optionsByType.addAll(platform.getOptions());
    // override with specified Options
    optionsByType.addAll(deploymentOptions);
    // initially there's no session
    Session session = null;
    try {
        // obtain the connected JSch Session
        session = sessionFactory.createSession(hostName, port, userName, authentication, socketFactory, optionsByType);
        if (deployedArtifacts.size() > 0) {
            ChannelSftp sftpChannel = null;
            try (DiagnosticsRecording diagnostics = DiagnosticsRecording.section("Remote Platform")) {
                // open an sftp channel that we can use to copy over the artifacts
                sftpChannel = (ChannelSftp) session.openChannel("sftp");
                sftpChannel.connect(session.getTimeout());
                for (File file : deployedArtifacts) {
                    try {
                        // attempt to delete the file
                        sftpChannel.rm(file.toString());
                        // include diagnostics
                        diagnostics.add(file.toString());
                    } catch (SftpException exception) {
                        try {
                            // attempt to remove the file as a directory
                            sftpChannel.rmdir(file.toString());
                            // include diagnostics (directory removed)
                            diagnostics.add(file.toString() + " (directory)");
                        } catch (SftpException e) {
                            // include diagnostics
                            diagnostics.add(file.toString() + " (failed to undeploy)");
                            failedArtifacts.add(file);
                        }
                    }
                }
            } finally {
                if (sftpChannel != null) {
                    sftpChannel.disconnect();
                }
            }
        }
    } catch (JSchException e) {
        throw new RuntimeException("Failed to undeploy application", e);
    } finally {
        if (session != null) {
            session.disconnect();
        }
    }
    return failedArtifacts;
}
Also used : DiagnosticsRecording(com.oracle.bedrock.diagnostics.DiagnosticsRecording) JSchException(com.jcraft.jsch.JSchException) DeployedArtifacts(com.oracle.bedrock.runtime.remote.DeployedArtifacts) SftpException(com.jcraft.jsch.SftpException) ChannelSftp(com.jcraft.jsch.ChannelSftp) Authentication(com.oracle.bedrock.runtime.remote.Authentication) OptionsByType(com.oracle.bedrock.OptionsByType) File(java.io.File) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) Session(com.jcraft.jsch.Session)

Aggregations

DeployedArtifacts (com.oracle.bedrock.runtime.remote.DeployedArtifacts)11 OptionsByType (com.oracle.bedrock.OptionsByType)10 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)6 Platform (com.oracle.bedrock.runtime.Platform)6 DeploymentArtifact (com.oracle.bedrock.runtime.remote.DeploymentArtifact)6 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)6 InetSocketAddress (java.net.InetSocketAddress)6 Test (org.junit.Test)6 File (java.io.File)4 HashMap (java.util.HashMap)3 ChannelSftp (com.jcraft.jsch.ChannelSftp)2 JSchException (com.jcraft.jsch.JSchException)2 Session (com.jcraft.jsch.Session)2 SftpException (com.jcraft.jsch.SftpException)2 PlatformSeparators (com.oracle.bedrock.runtime.options.PlatformSeparators)2 Authentication (com.oracle.bedrock.runtime.remote.Authentication)2 AbstractWindowsTest (com.oracle.bedrock.runtime.remote.winrm.AbstractWindowsTest)2 Table (com.oracle.bedrock.table.Table)2 IOException (java.io.IOException)2 DiagnosticsRecording (com.oracle.bedrock.diagnostics.DiagnosticsRecording)1