Search in sources :

Example 16 with Start

use of io.fabric8.arquillian.kubernetes.event.Start 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 17 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.

the class WatchAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (start && stop) {
        System.err.println("Please use only one of --start and --stop options!");
        return null;
    }
    if (interval > 0) {
        System.out.println("Setting watch interval to " + interval + " ms");
        watcher.setInterval(interval);
    }
    if (stop) {
        System.out.println("Stopping watch");
        watcher.stop();
    }
    watcher.setUpload(upload);
    if (urls != null) {
        if (remove) {
            for (String url : urls) {
                watcher.remove(url);
            }
        } else {
            for (String url : urls) {
                watcher.add(url);
            }
        }
    }
    if (start) {
        System.out.println("Starting watch");
        watcher.start();
    }
    if (list) {
        // list the watched bundles.
        TablePrinter printer = new TablePrinter();
        printer.columns("url", "profile", "version", "bundle");
        for (String url : watcher.getWatchURLs()) {
            Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = watcher.getProfileArtifacts();
            if (profileArtifacts.size() > 0) {
                Set<Map.Entry<ProfileVersionKey, Map<String, Parser>>> entries = profileArtifacts.entrySet();
                for (Map.Entry<ProfileVersionKey, Map<String, Parser>> entry : entries) {
                    ProfileVersionKey key = entry.getKey();
                    Map<String, Parser> artifactMap = entry.getValue();
                    Set<Map.Entry<String, Parser>> artifactMapEntries = artifactMap.entrySet();
                    for (Map.Entry<String, Parser> artifactMapEntry : artifactMapEntries) {
                        String location = artifactMapEntry.getKey();
                        Parser parser = artifactMapEntry.getValue();
                        if (isSnapshot(parser) || watcher.wildCardMatch(location, url)) {
                            printer.row(url, key.getProfileId(), key.getVersion(), location);
                        }
                    }
                }
            } else {
                printer.row(url, "", "", "");
            }
        }
        printer.print();
    } else {
        List<String> urls = watcher.getWatchURLs();
        if (urls != null && urls.size() > 0) {
            System.out.println("Watched URLs: ");
            for (String url : watcher.getWatchURLs()) {
                System.out.println(url);
            }
        } else {
            System.out.println("No watched URLs");
        }
    }
    return null;
}
Also used : ProfileVersionKey(io.fabric8.agent.commands.support.ProfileVersionKey) Parser(io.fabric8.maven.util.Parser) TablePrinter(io.fabric8.utils.TablePrinter) Map(java.util.Map)

Example 18 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.

the class ZooKeeperServerFactory method activateInternal.

private Destroyable activateInternal(BundleContext context, Map<String, ?> configuration) throws Exception {
    LOGGER.info("Creating zookeeper server with: {}", configuration);
    Properties props = new Properties();
    for (Entry<String, ?> entry : configuration.entrySet()) {
        props.put(entry.getKey(), entry.getValue());
    }
    // Remove the dependency on the current dir from dataDir
    String dataDir = props.getProperty("dataDir");
    if (dataDir != null && !Paths.get(dataDir).isAbsolute()) {
        dataDir = runtimeProperties.get().getDataPath().resolve(dataDir).toFile().getAbsolutePath();
        props.setProperty("dataDir", dataDir);
    }
    props.put("clientPortAddress", bootstrapConfiguration.get().getBindAddress());
    // Create myid file
    String serverId = (String) props.get("server.id");
    if (serverId != null) {
        props.remove("server.id");
        File myId = new File(dataDir, "myid");
        if (myId.exists() && !myId.delete()) {
            throw new IOException("Failed to delete " + myId);
        }
        if (myId.getParentFile() == null || (!myId.getParentFile().exists() && !myId.getParentFile().mkdirs())) {
            throw new IOException("Failed to create " + myId.getParent());
        }
        FileOutputStream fos = new FileOutputStream(myId);
        try {
            fos.write((serverId + "\n").getBytes());
        } finally {
            fos.close();
        }
    }
    QuorumPeerConfig peerConfig = getPeerConfig(props);
    if (!peerConfig.getServers().isEmpty()) {
        NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
        cnxnFactory.configure(peerConfig.getClientPortAddress(), peerConfig.getMaxClientCnxns());
        QuorumPeer quorumPeer = new QuorumPeer();
        quorumPeer.setClientPortAddress(peerConfig.getClientPortAddress());
        quorumPeer.setTxnFactory(new FileTxnSnapLog(new File(peerConfig.getDataLogDir()), new File(peerConfig.getDataDir())));
        quorumPeer.setQuorumPeers(peerConfig.getServers());
        quorumPeer.setElectionType(peerConfig.getElectionAlg());
        quorumPeer.setMyid(peerConfig.getServerId());
        quorumPeer.setTickTime(peerConfig.getTickTime());
        quorumPeer.setMinSessionTimeout(peerConfig.getMinSessionTimeout());
        quorumPeer.setMaxSessionTimeout(peerConfig.getMaxSessionTimeout());
        quorumPeer.setInitLimit(peerConfig.getInitLimit());
        quorumPeer.setSyncLimit(peerConfig.getSyncLimit());
        quorumPeer.setQuorumVerifier(peerConfig.getQuorumVerifier());
        quorumPeer.setCnxnFactory(cnxnFactory);
        quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
        quorumPeer.setLearnerType(peerConfig.getPeerType());
        try {
            LOGGER.debug("Starting quorum peer \"{}\" on address {}", quorumPeer.getMyid(), peerConfig.getClientPortAddress());
            quorumPeer.start();
            LOGGER.debug("Started quorum peer \"{}\"", quorumPeer.getMyid());
        } catch (Exception e) {
            LOGGER.warn("Failed to start quorum peer \"{}\", reason : {} ", quorumPeer.getMyid(), e.getMessage());
            quorumPeer.shutdown();
            throw e;
        }
        // Register stats provider
        ClusteredServer server = new ClusteredServer(quorumPeer);
        registration = context.registerService(QuorumStats.Provider.class, server, null);
        return server;
    } else {
        ServerConfig serverConfig = getServerConfig(peerConfig);
        ZooKeeperServer zkServer = new ZooKeeperServer();
        FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(serverConfig.getDataLogDir()), new File(serverConfig.getDataDir()));
        zkServer.setTxnLogFactory(ftxn);
        zkServer.setTickTime(serverConfig.getTickTime());
        zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());
        NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory() {

            protected void configureSaslLogin() throws IOException {
            }
        };
        cnxnFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
        try {
            LOGGER.debug("Starting ZooKeeper server on address {}", peerConfig.getClientPortAddress());
            cnxnFactory.startup(zkServer);
            LOGGER.debug("Started ZooKeeper server");
        } catch (Exception e) {
            LOGGER.warn("Failed to start ZooKeeper server, reason : {}", e);
            cnxnFactory.shutdown();
            throw e;
        }
        // Register stats provider
        SimpleServer server = new SimpleServer(zkServer, cnxnFactory);
        registration = context.registerService(ServerStats.Provider.class, server, null);
        startCleanupManager(serverConfig, props);
        return server;
    }
}
Also used : IOException(java.io.IOException) RuntimeProperties(io.fabric8.api.RuntimeProperties) Properties(java.util.Properties) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IOException(java.io.IOException) QuorumPeerConfig(org.apache.zookeeper.server.quorum.QuorumPeerConfig) FileOutputStream(java.io.FileOutputStream) QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer) File(java.io.File)

Example 19 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.

the class ContainerResource method stop.

/**
 * Stops the container
 */
@DELETE
@Path("start")
public void stop() {
    FabricService fabricService = getFabricService();
    Objects.notNull(fabricService, "fabricService");
    fabricService.stopContainer(container);
}
Also used : FabricService(io.fabric8.api.FabricService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 20 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.

the class FabricDTO method createContainerDTO.

public static ContainerDTO createContainerDTO(Container container, String baseApiLink) {
    ContainerDTO answer = new ContainerDTO();
    String containerId = container.getId();
    answer.setId(containerId);
    answer.setType(container.getType());
    answer.setChildren(Containers.containerIds(container.getChildren()));
    List<String> profileIds = Profiles.profileIds(container.getProfiles());
    String profileLinkPrefix = baseApiLink + "/version/" + Profiles.versionId(container.getVersion()) + "/profile/";
    answer.setProfiles(Links.mapIdsToLinks(profileIds, profileLinkPrefix));
    answer.setVersion(Profiles.versionId(container.getVersion()));
    answer.setParent(Containers.containerId(container.getParent()));
    answer.setIp(container.getIp());
    answer.setLocalIp(container.getLocalIp());
    answer.setManualIp(container.getManualIp());
    answer.setPublicIp(container.getPublicIp());
    answer.setLocalHostName(container.getLocalHostname());
    answer.setPublicHostName(container.getPublicHostname());
    answer.setResolver(container.getResolver());
    answer.setMaximumPort(container.getMaximumPort());
    answer.setMinimumPort(container.getMinimumPort());
    answer.setGeoLocation(container.getGeoLocation());
    answer.setLocation(container.getLocation());
    answer.setProcessId(container.getProcessId());
    answer.setDebugPort(container.getDebugPort());
    answer.setHttpUrl(container.getHttpUrl());
    answer.setJmxUrl(container.getJmxUrl());
    answer.setJolokiaUrl(container.getJolokiaUrl());
    answer.setSshUrl(container.getSshUrl());
    answer.setProvisionException(container.getProvisionException());
    answer.setProvisionResult(container.getProvisionResult());
    answer.setProvisionStatus(container.getProvisionStatus());
    answer.setProvisionList(container.getProvisionList());
    answer.setJmxDomains(container.getJmxDomains());
    answer.setAlive(container.isAlive());
    answer.setAliveAndOK(container.isAliveAndOK());
    answer.setEnsembleServer(container.isEnsembleServer());
    answer.setManaged(container.isManaged());
    answer.setProvisioningComplete(container.isProvisioningComplete());
    answer.setProvisioningPending(container.isProvisioningPending());
    answer.setRoot(container.isRoot());
    answer.setStartLink(baseApiLink + "/container/" + containerId + "/start");
    return answer;
}
Also used : ContainerDTO(io.fabric8.api.jmx.ContainerDTO)

Aggregations

Test (org.junit.Test)25 IOException (java.io.IOException)24 File (java.io.File)18 HashMap (java.util.HashMap)15 Map (java.util.Map)10 Git (org.eclipse.jgit.api.Git)10 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)8 ArrayList (java.util.ArrayList)8 Bundle (org.osgi.framework.Bundle)8 PatchException (io.fabric8.patch.management.PatchException)7 URISyntaxException (java.net.URISyntaxException)7 BundleException (org.osgi.framework.BundleException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 CuratorFramework (org.apache.curator.framework.CuratorFramework)6 Container (io.fabric8.api.Container)5 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)5 FabricService (io.fabric8.api.FabricService)5 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)5 MalformedURLException (java.net.MalformedURLException)5 URI (java.net.URI)5