Search in sources :

Example 81 with Container

use of io.fabric8.api.Container in project fabric8 by jboss-fuse.

the class CloudFirewallEdit method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (validateArguments()) {
        ComputeService computeService = findTargetComputeService();
        if (computeService == null) {
            return null;
        }
        Set<String> sourceCidrs = collectCirds();
        FirewallManager firewallManager = firewallManagerFactory.getFirewallManager(computeService);
        NodeMetadata node = null;
        if (!Strings.isNullOrEmpty(targetContainerName) && getCurator().getZookeeperClient().isConnected() && fabricService != null) {
            CreateJCloudsContainerMetadata metadata = getContainerCloudMetadata(targetContainerName);
            if (metadata != null && !Strings.isNullOrEmpty(metadata.getNodeId())) {
                targetNodeId = metadata.getNodeId();
            }
        }
        if (!Strings.isNullOrEmpty(targetNodeId)) {
            node = computeService.getNodeMetadata(targetNodeId);
        }
        if (node == null) {
            System.err.println("Could not find target node. Make sure you specified either --target-node-id or --target-container using a valid cloud container.");
            return null;
        }
        if (flush) {
            firewallManager.addRule(Rule.create().destination(node).flush());
            return null;
        }
        for (String cidr : sourceCidrs) {
            Rule rule = Rule.create().destination(node).source(cidr);
            if (port != null && port.length > 0) {
                rule = rule.ports(port);
            }
            if (revoke) {
                firewallManager.addRule(rule.revoke());
            } else {
                firewallManager.addRule(rule);
            }
        }
    }
    return null;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) FirewallManager(io.fabric8.service.jclouds.firewall.FirewallManager) CreateJCloudsContainerMetadata(io.fabric8.service.jclouds.CreateJCloudsContainerMetadata) Rule(io.fabric8.service.jclouds.firewall.Rule) ComputeService(org.jclouds.compute.ComputeService)

Example 82 with Container

use of io.fabric8.api.Container in project fabric8 by jboss-fuse.

the class SshContainerCompleter method getProvider.

private ContainerProvider getProvider(Container container) {
    CreateContainerMetadata metadata = container.getMetadata();
    String type = metadata != null ? metadata.getCreateOptions().getProviderType() : null;
    if (type == null) {
        return null;
    }
    ContainerProvider provider = fabricService.getProvider(type);
    if (provider == null) {
        return null;
    }
    return provider;
}
Also used : ContainerProvider(io.fabric8.api.ContainerProvider) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata)

Example 83 with Container

use of io.fabric8.api.Container in project fabric8 by jboss-fuse.

the class SshContainerProvider method start.

@Override
public void start(Container container) {
    CreateContainerMetadata metadata = container.getMetadata();
    if (!(metadata instanceof CreateSshContainerMetadata)) {
        throw new IllegalStateException("Container doesn't have valid create container metadata type");
    } else {
        CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
        CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
        Session session = null;
        try {
            String script = buildStartScript(container.getId(), options);
            session = createSession(options);
            runScriptOnHost(session, script);
        } catch (Throwable t) {
            LOGGER.error("Failed to start container: " + container.getId(), t);
            throw new FabricException(t);
        } finally {
            if (session != null) {
                session.disconnect();
            }
        }
    }
}
Also used : CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) Session(com.jcraft.jsch.Session)

Example 84 with Container

use of io.fabric8.api.Container in project fabric8 by jboss-fuse.

the class SshContainerProvider method destroy.

@Override
public void destroy(Container container) {
    CreateContainerMetadata metadata = container.getMetadata();
    if (!(metadata instanceof CreateSshContainerMetadata)) {
        throw new IllegalStateException("Container doesn't have valid create container metadata type");
    } else {
        CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
        CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
        Session session = null;
        String prevProvisionResult = container.getProvisionResult();
        try {
            String script = buildUninstallScript(container.getId(), options);
            session = createSession(options);
            container.setProvisionResult(Container.PROVISION_DELETING);
            runScriptOnHost(session, script);
        } catch (Throwable t) {
            LOGGER.error("Failed to stop container: " + container.getId(), t);
            throw new FabricException(t);
        } finally {
            if (session != null) {
                session.disconnect();
            }
        }
    }
}
Also used : CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) Session(com.jcraft.jsch.Session)

Example 85 with Container

use of io.fabric8.api.Container in project fabric8 by jboss-fuse.

the class SshContainerProvider method stop.

@Override
public void stop(Container container) {
    CreateContainerMetadata metadata = container.getMetadata();
    if (!(metadata instanceof CreateSshContainerMetadata)) {
        throw new IllegalStateException("Container doesn't have valid create container metadata type");
    } else {
        CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
        CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
        Session session = null;
        try {
            String script = buildStopScript(container.getId(), options);
            session = createSession(options);
            container.setProvisionResult(Container.PROVISION_STOPPING);
            runScriptOnHost(session, script);
            container.setProvisionResult(Container.PROVISION_STOPPED);
        } catch (Throwable t) {
            LOGGER.error("Failed to stop container: " + container.getId(), t);
            throw new FabricException(t);
        } finally {
            if (session != null) {
                session.disconnect();
            }
        }
    }
}
Also used : CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) Session(com.jcraft.jsch.Session)

Aggregations

Container (io.fabric8.api.Container)139 Test (org.junit.Test)75 FabricService (io.fabric8.api.FabricService)56 ArrayList (java.util.ArrayList)39 Container (io.fabric8.kubernetes.api.model.Container)38 IOException (java.io.IOException)38 Profile (io.fabric8.api.Profile)37 HashMap (java.util.HashMap)34 Map (java.util.Map)30 FabricException (io.fabric8.api.FabricException)27 BundleContext (org.osgi.framework.BundleContext)24 Version (io.fabric8.api.Version)23 File (java.io.File)23 HashSet (java.util.HashSet)20 LinkedList (java.util.LinkedList)17 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)16 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)16 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)15 Pod (io.fabric8.kubernetes.api.model.Pod)12 List (java.util.List)12