Search in sources :

Example 36 with Server

use of io.fabric8.insight.metrics.model.Server in project camel by apache.

the class KubernetesReplicationControllersConsumerTest method createAndDeleteReplicationController.

@Test
public void createAndDeleteReplicationController() throws Exception {
    if (ObjectHelper.isEmpty(authToken)) {
        return;
    }
    mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "DELETED", "MODIFIED", "MODIFIED", "MODIFIED");
    Exchange ex = template.request("direct:createReplicationController", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, "test");
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("this", "rocks");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, labels);
            ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
            rcSpec.setReplicas(2);
            PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
            PodTemplateSpec t = builder.withNewMetadata().withName("nginx-template").addToLabels("server", "nginx").endMetadata().withNewSpec().addNewContainer().withName("wildfly").withImage("jboss/wildfly").addNewPort().withContainerPort(80).endPort().endContainer().endSpec().build();
            rcSpec.setTemplate(t);
            Map<String, String> selectorMap = new HashMap<String, String>();
            selectorMap.put("server", "nginx");
            rcSpec.setSelector(selectorMap);
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC, rcSpec);
        }
    });
    ReplicationController rc = ex.getOut().getBody(ReplicationController.class);
    assertEquals(rc.getMetadata().getName(), "test");
    ex = template.request("direct:deleteReplicationController", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
            exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, "test");
        }
    });
    boolean rcDeleted = ex.getOut().getBody(Boolean.class);
    assertTrue(rcDeleted);
    Thread.sleep(3000);
    mockResultEndpoint.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Processor(org.apache.camel.Processor) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) HashMap(java.util.HashMap) Map(java.util.Map) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec) Test(org.junit.Test)

Example 37 with Server

use of io.fabric8.insight.metrics.model.Server in project syndesis-qe by syndesisio.

the class AmqTemplate method deploy.

public static void deploy() {
    Template template = null;
    try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-amq.yml")) {
        template = OpenShiftUtils.client().templates().load(is).get();
    } catch (IOException ex) {
        throw new IllegalArgumentException("Unable to read template ", ex);
    }
    Map<String, String> templateParams = new HashMap<>();
    templateParams.put("MQ_USERNAME", "amq");
    templateParams.put("MQ_PASSWORD", "topSecret");
    // try to clean previous broker
    cleanUp();
    OpenShiftUtils.client().templates().withName("syndesis-amq").delete();
    KubernetesList processedTemplate = OpenShiftUtils.getInstance().recreateAndProcessTemplate(template, templateParams);
    OpenShiftUtils.getInstance().createResources(processedTemplate);
    try {
        OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.isAPodReady("application", "broker"));
    } catch (InterruptedException | TimeoutException e) {
        log.error("Wait for syndesis-server failed ", e);
    }
    // this is not part of deployment, but let's have it the same method:
    AmqTemplate.addAccounts();
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Template(io.fabric8.openshift.api.model.Template) TimeoutException(java.util.concurrent.TimeoutException)

Example 38 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class ZooKeeperUtils method generateContainerToken.

public static String generateContainerToken(RuntimeProperties sysprops, CuratorFramework curator) {
    String container = sysprops.getRuntimeIdentity();
    long time = System.currentTimeMillis();
    String password = null;
    try {
        if (time - lastTokenGenerationTime < 60 * 1000) {
            try {
                password = getStringData(curator, CONTAINERS_NODE + "/" + container);
            } catch (KeeperException.NoNodeException ex) {
            // Node hasn't been created yet. It's safe to ignore.
            }
        }
        if (password == null) {
            password = generatePassword();
            setData(curator, CONTAINERS_NODE + "/" + container, password);
            lastTokenGenerationTime = time;
        }
    } catch (KeeperException.NotReadOnlyException e) {
        throw new FabricException("ZooKeeper server is partitioned. Currently working in read-only mode!");
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception ex) {
        throw new IllegalStateException("Cannot generate container token", ex);
    }
    return password;
}
Also used : FabricException(io.fabric8.api.FabricException) KeeperException(org.apache.zookeeper.KeeperException) URISyntaxException(java.net.URISyntaxException) FabricException(io.fabric8.api.FabricException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 39 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class ProfileCopyAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    // but validate the target name
    try {
        FabricValidations.validateProfileName(target);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    Version version = versionParam != null ? profileService.getRequiredVersion(versionParam) : fabricService.getRequiredDefaultVersion();
    String versionId = version.getId();
    if (!version.hasProfile(source)) {
        System.out.println("Source profile " + source + " not found.");
        return 1;
    } else if (version.hasProfile(target)) {
        if (!force) {
            System.out.println("Target profile " + target + " already exists. Use --force if you want to overwrite.");
            return null;
        }
    }
    Profiles.copyProfile(fabricService, versionId, source, target, force);
    return null;
}
Also used : Version(io.fabric8.api.Version)

Example 40 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class ProfileCreateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(profileId);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    if (versionId != null) {
        profileService.getRequiredVersion(versionId);
    } else {
        versionId = fabricService.getDefaultVersionId();
    }
    // we can only use existing parent profiles
    Profile[] parents = FabricCommand.getExistingProfiles(fabricService, versionId, this.parents);
    ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId);
    for (Profile parent : parents) {
        builder.addParent(parent.getId());
    }
    profileService.createProfile(builder.getProfile());
    return null;
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Aggregations

HashMap (java.util.HashMap)20 Test (org.junit.Test)19 IOException (java.io.IOException)18 File (java.io.File)9 Map (java.util.Map)9 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 ArrayList (java.util.ArrayList)8 Profile (io.fabric8.api.Profile)7 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 DispatchQueue (org.fusesource.hawtdispatch.DispatchQueue)7 Container (io.fabric8.api.Container)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 Version (io.fabric8.api.Version)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 FabricException (io.fabric8.api.FabricException)4 RuntimeProperties (io.fabric8.api.RuntimeProperties)4 InputStream (java.io.InputStream)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3