Search in sources :

Example 51 with Template

use of io.fabric8.openshift.api.model.Template in project vertx-openshift-it by cescoffier.

the class OpenShiftTestAssistant method deploy.

public List<? extends HasMetadata> deploy(String name, File template) throws IOException {
    try (FileInputStream fis = new FileInputStream(template)) {
        List<HasMetadata> entities = client.load(fis).createOrReplace();
        created.put(name, entities);
        System.out.println(name + " deployed, " + entities.size() + " object(s) created.");
        return entities;
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) FileInputStream(java.io.FileInputStream)

Example 52 with Template

use of io.fabric8.openshift.api.model.Template in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method activateInternal.

private void activateInternal() throws Exception {
    LOGGER.info("Starting up GitDataStore " + this);
    // Call the bootstrap {@link DataStoreTemplate}
    DataStoreTemplate template = runtimeProperties.get().removeRuntimeAttribute(DataStoreTemplate.class);
    if (template != null) {
        // Do the initial commit and set the root tag
        Ref rootTag = getGit().getRepository().getRef(GitHelpers.ROOT_TAG);
        if (rootTag == null) {
            getGit().commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
            getGit().tag().setName(GitHelpers.ROOT_TAG).setMessage("Tag the root commit").call();
        }
        LOGGER.debug("Running datastore bootstrap template: " + template);
        template.doWith(this, dataStore.get());
    }
    // Setup proxy service
    GitProxyService proxyService = gitProxyService.get();
    defaultProxySelector = ProxySelector.getDefault();
    // authenticator disabled, until properly tested it does not affect others, as Authenticator is static in the JVM
    // Authenticator.setDefault(new FabricGitLocalHostAuthenticator(proxyService));
    ProxySelector fabricProxySelector = new FabricGitLocalHostProxySelector(defaultProxySelector, proxyService);
    ProxySelector.setDefault(fabricProxySelector);
    LOGGER.debug("Setting up FabricProxySelector: {}", fabricProxySelector);
    if (gitRemoteUrl != null) {
        gitListener.runRemoteUrlChanged(gitRemoteUrl);
        remoteUrl = gitRemoteUrl;
    } else {
        gitService.get().addGitListener(gitListener);
        remoteUrl = gitService.get().getRemoteUrl();
        if (remoteUrl != null) {
            gitListener.runRemoteUrlChanged(remoteUrl);
        }
    }
    // Get initial versions
    getInitialVersions();
    // poll logic in case of remote git repo
    if (gitRemoteUrl != null) {
        // i need this old logic in case of remote repos
        LOGGER.info("Starting to pull from remote git repository every {} millis", gitRemotePollInterval);
        threadPool.scheduleWithFixedDelay(new Runnable() {

            @Override
            public void run() {
                LockHandle writeLock = aquireWriteLock();
                try {
                    LOGGER.trace("Performing timed pull");
                    doPullInternal();
                    LOGGER.debug("Performed timed pull from external git repo");
                } catch (Throwable e) {
                    LOGGER.debug("Error during performed timed pull/push due " + e.getMessage(), e);
                    LOGGER.warn("Error during performed timed pull/push due " + e.getMessage() + ". This exception is ignored.");
                } finally {
                    writeLock.unlock();
                }
            }

            @Override
            public String toString() {
                return "TimedPushTask";
            }
        }, 1000, gitRemotePollInterval, TimeUnit.MILLISECONDS);
    }
    LOGGER.info("Using ZooKeeper SharedCount to react when master git repo is changed, so we can do a git pull to the local git repo.");
    counter = new SharedCount(curator.get(), ZkPath.GIT_TRIGGER.getPath(), 0);
    counter.addListener(new SharedCountListener() {

        @Override
        public void countHasChanged(final SharedCountReader sharedCountReader, final int value) throws Exception {
            Runnable task = new Runnable() {

                @Override
                public void run() {
                    doPullInternal();
                }
            };
            if (gitRandomFetchDelay == 0) {
                LOGGER.debug("Watch counter updated to " + value + ", scheduling immediate pull");
                threadPool.submit(task);
            } else {
                int delay = RND.nextInt(gitRandomFetchDelay) + 1;
                LOGGER.debug("Watch counter updated to " + value + ", scheduling pull with random delay=" + delay + "s");
                threadPool.schedule(task, delay, TimeUnit.SECONDS);
            }
        }

        @Override
        public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
            switch(connectionState) {
                case SUSPENDED:
                case READ_ONLY:
                case LOST:
                    // do nothing
                    break;
                case CONNECTED:
                case RECONNECTED:
                    LOGGER.info("Shared Counter (Re)connected, doing a pull");
                    doPullInternal();
                    break;
            }
        }
    });
    try {
        counter.start();
    } catch (KeeperException.NotReadOnlyException ex) {
    // In read only mode the counter is not going to start.
    // If the connection is reestablished the component will reactivate.
    // We need to catch this error so that the component gets activated.
    }
    if (gitGcOnLoad) {
        LockHandle writeLock = aquireWriteLock();
        try {
            GitOperation<Void> gitop = new GitOperation<Void>() {

                public Void call(Git git, GitContext context) throws Exception {
                    long before = System.currentTimeMillis();
                    try {
                        git.gc().call();
                        LOGGER.debug("git gc took " + ((System.currentTimeMillis() - before)) + " ms.");
                    } catch (GitAPIException e) {
                        LOGGER.debug("git gc threw an exception!", e);
                    }
                    return null;
                }
            };
            executeInternal(new GitContext(), null, gitop);
        } finally {
            writeLock.unlock();
        }
    }
    // failing to activate the component
    if (readWriteLock.isWriteLockedByCurrentThread() || readWriteLock.getWriteHoldCount() == 0) {
        try {
            // let's delegate to other thread in order to free MCF thread
            // ENTESB-7843: there's a problem when jetty is configured with TLS and keystore location using
            // profile: URI. while Jetty continues to be configured if profile:jetty.xml isn't available
            // (and it isn't initially), it fails trying to access keystore via profile: URI.
            // we should optimistically assume we can pull, but there's nothing wrong if we can't
            // - we'll be able to pull later
            threadPoolInitial.execute(new Runnable() {

                @Override
                public void run() {
                    doPullInternal(5);
                }
            });
        } catch (IllegalStateException e) {
            LOGGER.info("Another thread acquired write lock and GitDataStore can't pull from remote repository.");
        }
    } else {
        LOGGER.info("Another thread is keeping git write lock. GitDataStore will continue activation.");
    }
}
Also used : SharedCount(org.apache.curator.framework.recipes.shared.SharedCount) ProxySelector(java.net.ProxySelector) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) CuratorFramework(org.apache.curator.framework.CuratorFramework) DataStoreTemplate(io.fabric8.api.DataStoreTemplate) SharedCountListener(org.apache.curator.framework.recipes.shared.SharedCountListener) GitProxyService(io.fabric8.git.GitProxyService) LockHandle(io.fabric8.api.LockHandle) SharedCountReader(org.apache.curator.framework.recipes.shared.SharedCountReader) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) FabricException(io.fabric8.api.FabricException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext) ConnectionState(org.apache.curator.framework.state.ConnectionState) KeeperException(org.apache.zookeeper.KeeperException)

Example 53 with Template

use of io.fabric8.openshift.api.model.Template in project fabric8 by jboss-fuse.

the class CamelProfileLongTest method testFeatures.

@Test
public void testFeatures() throws Exception {
    System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
    // System.out.println(executeCommand("shell:info"));
    // System.out.println(executeCommand("fabric:info"));
    // System.out.println(executeCommand("fabric:profile-list"));
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy).withName("feautre-camel").withProfiles("default").assertProvisioningResult().build();
        try {
            prepareFeaturesForTesting(containers, "camel-blueprint", "feautre-camel", "camel-blueprint");
            prepareFeaturesForTesting(containers, "camel-jms", "feautre-camel", "camel-jms");
            prepareFeaturesForTesting(containers, "camel-http", "feautre-camel", "camel-http");
            prepareFeaturesForTesting(containers, "camel-cxf", "feautre-camel", "camel-cxf");
            prepareFeaturesForTesting(containers, "camel-cache", "feautre-camel", "camel-cache");
            prepareFeaturesForTesting(containers, "camel-castor", "feautre-camel", "camel-castor");
            prepareFeaturesForTesting(containers, "camel-http", "feautre-camel", "camel-http");
            prepareFeaturesForTesting(containers, "camel-http4", "feautre-camel", "camel-http4");
            prepareFeaturesForTesting(containers, "camel-mina", "feautre-camel", "camel-mina");
            prepareFeaturesForTesting(containers, "camel-jetty", "feautre-camel", "camel-jetty");
            prepareFeaturesForTesting(containers, "camel-servlet", "feautre-camel", "camel-servlet");
            prepareFeaturesForTesting(containers, "camel-jms", "feautre-camel", "camel-jms");
            prepareFeaturesForTesting(containers, "camel-jmx", "feautre-camel", "camel-jmx");
            prepareFeaturesForTesting(containers, "camel-ahc", "feautre-camel", "camel-ahc");
            prepareFeaturesForTesting(containers, "camel-amqp", "feautre-camel", "camel-amqp");
            prepareFeaturesForTesting(containers, "camel-atom", "feautre-camel", "camel-atom");
            prepareFeaturesForTesting(containers, "camel-aws", "feautre-camel", "camel-aws");
            prepareFeaturesForTesting(containers, "camel-bam", "feautre-camel", "camel-bam");
            prepareFeaturesForTesting(containers, "camel-bean-validator", "feautre-camel", "camel-bean-validator");
            prepareFeaturesForTesting(containers, "camel-bindy", "feautre-camel", "camel-bindy");
            prepareFeaturesForTesting(containers, "camel-cometd", "feautre-camel", "camel-cometd");
            prepareFeaturesForTesting(containers, "camel-csv", "feautre-camel", "camel-csv");
            prepareFeaturesForTesting(containers, "camel-dozer", "feautre-camel", "camel-dozer");
            prepareFeaturesForTesting(containers, "camel-eventadmin", "feautre-camel", "camel-eventadmin");
            prepareFeaturesForTesting(containers, "camel-exec", "feautre-camel", "camel-exec");
            prepareFeaturesForTesting(containers, "camel-flatpack", "feautre-camel", "camel-flatpack");
            prepareFeaturesForTesting(containers, "camel-freemarker", "feautre-camel", "camel-freemarker");
            prepareFeaturesForTesting(containers, "camel-ftp", "feautre-camel", "camel-ftp");
            prepareFeaturesForTesting(containers, "camel-guice", "feautre-camel", "camel-guice");
            prepareFeaturesForTesting(containers, "camel-groovy", "feautre-camel", "camel-groovy");
            prepareFeaturesForTesting(containers, "camel-hazelcast", "feautre-camel", "camel-hazelcast");
            prepareFeaturesForTesting(containers, "camel-hawtdb", "feautre-camel", "camel-hawtdb");
            prepareFeaturesForTesting(containers, "camel-hdfs", "feautre-camel", "camel-hdfs");
            prepareFeaturesForTesting(containers, "camel-hl7", "feautre-camel", "camel-hl7");
            prepareFeaturesForTesting(containers, "camel-ibatis", "feautre-camel", "camel-ibatis");
            prepareFeaturesForTesting(containers, "camel-irc", "feautre-camel", "camel-irc");
            prepareFeaturesForTesting(containers, "camel-jackson", "feautre-camel", "camel-jackson");
            prepareFeaturesForTesting(containers, "camel-jasypt", "feautre-camel", "camel-jasypt");
            prepareFeaturesForTesting(containers, "camel-jaxb", "feautre-camel", "camel-jaxb");
            prepareFeaturesForTesting(containers, "camel-jclouds", "feautre-camel", "camel-jclouds");
            prepareFeaturesForTesting(containers, "camel-jcr", "feautre-camel", "camel-jcr");
            prepareFeaturesForTesting(containers, "camel-jing", "feautre-camel", "camel-jing");
            prepareFeaturesForTesting(containers, "camel-jibx", "feautre-camel", "camel-jibx");
            prepareFeaturesForTesting(containers, "camel-jdbc", "feautre-camel", "camel-jdbc");
            prepareFeaturesForTesting(containers, "camel-josql", "feautre-camel", "camel-josql");
            prepareFeaturesForTesting(containers, "camel-josql", "feautre-camel", "camel-josql");
            prepareFeaturesForTesting(containers, "camel-jpa", "feautre-camel", "camel-jpa");
            prepareFeaturesForTesting(containers, "camel-jxpath", "feautre-camel", "camel-jxpath");
            prepareFeaturesForTesting(containers, "camel-juel", "feautre-camel", "camel-juel");
            prepareFeaturesForTesting(containers, "camel-kestrel", "feautre-camel", "camel-kestrel");
            prepareFeaturesForTesting(containers, "camel-krati", "feautre-camel", "camel-krati");
            prepareFeaturesForTesting(containers, "camel-ldap", "feautre-camel", "camel-ldap");
            prepareFeaturesForTesting(containers, "camel-lucene", "feautre-camel", "camel-lucene");
            prepareFeaturesForTesting(containers, "camel-mail", "feautre-camel", "camel-mail");
            prepareFeaturesForTesting(containers, "camel-msv", "feautre-camel", "camel-msv");
            prepareFeaturesForTesting(containers, "camel-mvel", "feautre-camel", "camel-mvel");
            prepareFeaturesForTesting(containers, "camel-mybatis", "feautre-camel", "camel-mybatis");
            prepareFeaturesForTesting(containers, "camel-nagios", "feautre-camel", "camel-nagios");
            prepareFeaturesForTesting(containers, "camel-netty", "feautre-camel", "camel-netty");
            prepareFeaturesForTesting(containers, "camel-ognl", "feautre-camel", "camel-ognl");
            prepareFeaturesForTesting(containers, "camel-paxlogging", "feautre-camel", "camel-paxlogging");
            prepareFeaturesForTesting(containers, "camel-printer", "feautre-camel", "camel-printer");
            prepareFeaturesForTesting(containers, "camel-protobuf", "feautre-camel", "camel-protobuf");
            prepareFeaturesForTesting(containers, "camel-quartz", "feautre-camel", "camel-quartz");
            prepareFeaturesForTesting(containers, "camel-quickfix", "feautre-camel", "camel-quickfix");
            prepareFeaturesForTesting(containers, "camel-restlet", "feautre-camel", "camel-restlet");
            prepareFeaturesForTesting(containers, "camel-rmi", "feautre-camel", "camel-rmi");
            prepareFeaturesForTesting(containers, "camel-routebox", "feautre-camel", "camel-routebox");
            prepareFeaturesForTesting(containers, "camel-ruby", "feautre-camel", "org.jruby.jruby");
            prepareFeaturesForTesting(containers, "camel-rss", "feautre-camel", "camel-rss");
            prepareFeaturesForTesting(containers, "camel-saxon", "feautre-camel", "camel-saxon");
            prepareFeaturesForTesting(containers, "camel-scala", "feautre-camel", "camel-scala");
            prepareFeaturesForTesting(containers, "camel-script", "feautre-camel", "camel-script");
            prepareFeaturesForTesting(containers, "camel-sip", "feautre-camel", "camel-sip");
            prepareFeaturesForTesting(containers, "camel-shiro", "feautre-camel", "camel-shiro");
            prepareFeaturesForTesting(containers, "camel-smpp", "feautre-camel", "camel-smpp");
            prepareFeaturesForTesting(containers, "camel-snmp", "feautre-camel", "camel-snmp");
            prepareFeaturesForTesting(containers, "camel-soap", "feautre-camel", "camel-soap");
            prepareFeaturesForTesting(containers, "camel-solr", "feautre-camel", "camel-solr");
            prepareFeaturesForTesting(containers, "camel-spring-integration", "feautre-camel", "camel-spring-integration");
            prepareFeaturesForTesting(containers, "camel-spring-javaconfig", "feautre-camel", "camel-spring-javaconfig");
            prepareFeaturesForTesting(containers, "camel-spring-security", "feautre-camel", "camel-spring-security");
            prepareFeaturesForTesting(containers, "camel-spring-ws", "feautre-camel", "camel-spring-ws");
            prepareFeaturesForTesting(containers, "camel-sql", "feautre-camel", "camel-sql");
            prepareFeaturesForTesting(containers, "camel-stax", "feautre-camel", "camel-stax");
            prepareFeaturesForTesting(containers, "camel-stream", "feautre-camel", "camel-stream");
            prepareFeaturesForTesting(containers, "camel-string-template", "feautre-camel", "org.apache.servicemix.bundles.stringtemplate");
            prepareFeaturesForTesting(containers, "camel-syslog", "feautre-camel", "camel-syslog");
            prepareFeaturesForTesting(containers, "camel-tagsoup", "feautre-camel", "camel-tagsoup");
            prepareFeaturesForTesting(containers, "camel-velocity", "feautre-camel", "camel-velocity");
            prepareFeaturesForTesting(containers, "camel-xmlbeans", "feautre-camel", "camel-xmlbeans");
            prepareFeaturesForTesting(containers, "camel-xmlsecurity", "feautre-camel", "camel-xmlsecurity");
            prepareFeaturesForTesting(containers, "camel-xmpp", "feautre-camel", "camel-xmpp");
            prepareFeaturesForTesting(containers, "camel-xstream", "feautre-camel", "camel-xstream");
            prepareFeaturesForTesting(containers, "camel-zookeeper", "feautre-camel", "camel-zookeeper");
            // prepareFeaturesForTesting(containers, "camel-crypto", "feautre-camel", "camel-crypto");
            // prepareFeaturesForTesting(containers, "camel-script camel-script-jruby", "feautre-camel", "camel-script-jruby");
            // prepareFeaturesForTesting(containers, "camel-script camel-script-javascript", "feautre-camel", "camel-script-javascript");
            // prepareFeaturesForTesting(containers, "camel-script camel-script-groovy", "feautre-camel", "camel-script-groovy");
            assertFeatures(fabricService, curator);
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) FabricFeaturesTest(io.fabric8.itests.paxexam.support.FabricFeaturesTest) Test(org.junit.Test)

Example 54 with Template

use of io.fabric8.openshift.api.model.Template in project fabric8 by jboss-fuse.

the class ContainerTest method testLoadBalancer.

@Test
public void testLoadBalancer() throws Exception {
    Profiler profiler = new Profiler();
    Breadcrumbs breadcrumbs = new Breadcrumbs();
    CamelContext context = new DefaultCamelContext();
    profiler.manage(context);
    breadcrumbs.manage(context);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:a").loadBalance().failover().to("mock:out");
        }
    });
    context.start();
    final ProducerTemplate template = new DefaultProducerTemplate(context);
    template.start();
    template.sendBody("direct:a", "Hello");
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) ProducerTemplate(org.apache.camel.ProducerTemplate) Profiler(io.fabric8.insight.camel.profiler.Profiler) RouteBuilder(org.apache.camel.builder.RouteBuilder) Breadcrumbs(io.fabric8.insight.camel.breadcrumb.Breadcrumbs) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Example 55 with Template

use of io.fabric8.openshift.api.model.Template in project jointware by isdream.

the class PerfComparator method createByObject.

public static void createByObject() {
    Deployment dm = new Deployment();
    {
        ObjectMeta md = new ObjectMeta();
        ;
        md.setName("busybox-dm");
        md.setNamespace("wuheng");
        {
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("app", "busybox-dm");
            md.setLabels(labels);
        }
        dm.setMetadata(md);
    }
    {
        DeploymentSpec spec = new DeploymentSpec();
        spec.setReplicas(2);
        {
            PodTemplateSpec template = new PodTemplateSpec();
            {
                PodSpec pc = new PodSpec();
                {
                    List<Container> containers = new ArrayList<Container>();
                    {
                        Container c = new Container();
                        {
                            c.setImage("dcr.io:5000/busybox:latest");
                            c.setImagePullPolicy("IfNotPresent");
                            c.setName("busybox-dm");
                            List<String> commands = new ArrayList<String>();
                            {
                                commands.add("sleep");
                                commands.add("3600");
                            }
                            c.setCommand(commands);
                        }
                        containers.add(c);
                    }
                    pc.setContainers(containers);
                }
                template.setSpec(pc);
            }
            spec.setTemplate(template);
        }
        dm.setSpec(spec);
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Container(io.fabric8.kubernetes.api.model.Container) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) HashMap(java.util.HashMap) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment)

Aggregations

Template (io.fabric8.openshift.api.model.Template)23 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)19 File (java.io.File)14 IOException (java.io.IOException)13 HashMap (java.util.HashMap)12 Test (org.junit.Test)12 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)11 Service (io.fabric8.kubernetes.api.model.Service)10 Container (io.fabric8.kubernetes.api.model.Container)8 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 OpenShiftHelper (io.vertx.it.openshift.utils.OpenShiftHelper)7 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 BeforeClass (org.junit.BeforeClass)7 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)6 TreeMap (java.util.TreeMap)6 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)5 Parameter (io.fabric8.openshift.api.model.Parameter)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4