Search in sources :

Example 11 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project fabric8 by jboss-fuse.

the class MQManager method createConfigDTOs.

public static List<MQBrokerConfigDTO> createConfigDTOs(MQService mqService, Profile profile) {
    List<MQBrokerConfigDTO> answer = new ArrayList<MQBrokerConfigDTO>();
    Map<String, Map<String, String>> configurations = profile.getConfigurations();
    Set<Map.Entry<String, Map<String, String>>> entries = configurations.entrySet();
    for (Map.Entry<String, Map<String, String>> entry : entries) {
        String key = entry.getKey();
        Map<String, String> configuration = entry.getValue();
        if (isBrokerConfigPid(key)) {
            String brokerName = getBrokerNameFromPID(key);
            String profileId = profile.getId();
            MQBrokerConfigDTO dto = new MQBrokerConfigDTO();
            dto.setProfile(profileId);
            dto.setBrokerName(brokerName);
            String version = profile.getVersion();
            dto.setVersion(version);
            List<String> parentIds = profile.getParentIds();
            if (parentIds.size() > 0) {
                dto.setParentProfile(parentIds.get(0));
            }
            if (configuration != null) {
                dto.setData(configuration.get(DATA));
                dto.setConfigUrl(configuration.get(CONFIG_URL));
                dto.setGroup(configuration.get(GROUP));
                dto.setKind(BrokerKind.fromValue(configuration.get(KIND)));
                dto.setMinimumInstances(Maps.integerValue(configuration, MINIMUM_INSTANCES));
                dto.setNetworks(Maps.stringValues(configuration, NETWORKS));
                dto.setNetworksUserName(configuration.get(NETWORK_USER_NAME));
                dto.setNetworksPassword(configuration.get(NETWORK_PASSWORD));
                dto.setReplicas(Maps.integerValue(configuration, REPLICAS));
                for (Map.Entry<String, String> configurationEntry : configuration.entrySet()) {
                    if (configurationEntry.getKey().endsWith("-port")) {
                        dto.getPorts().put(configurationEntry.getKey().substring(0, configurationEntry.getKey().indexOf("-port")), configurationEntry.getValue());
                    }
                }
            }
            answer.add(dto);
        }
    }
    return answer;
}
Also used : MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project fabric8 by jboss-fuse.

the class ContainerCreateCloud method doExecute.

@Override
protected Object doExecute() throws Exception {
    // validate input before creating containers
    preCreateContainer(name);
    FabricValidations.validateProfileNames(profiles);
    if (isEnsembleServer && newUserPassword == null) {
        newUserPassword = zookeeperPassword != null ? zookeeperPassword : fabricService.getZookeeperPassword();
    }
    CreateJCloudsContainerOptions.Builder builder = CreateJCloudsContainerOptions.builder().name(name).bindAddress(bindAddress).resolver(resolver).manualIp(manualIp).ensembleServer(isEnsembleServer).credential(credential).group(group).hardwareId(hardwareId).identity(identity).osFamily(osFamily).osVersion(osVersion).imageId(imageId).instanceType(instanceType).locationId(locationId).number(number).nodeOptions(CloudUtils.parseProviderOptions(options)).owner(owner).adminAccess(!disableAdminAccess).publicKeyFile(publicKeyFile).contextName(contextName).providerName(providerName).apiName(apiName).user(user).password(password).proxyUri(proxyUri != null ? proxyUri : fabricService.getMavenRepoURI()).zookeeperUrl(fabricService.getZookeeperUrl()).zookeeperPassword(isEnsembleServer && zookeeperPassword != null ? zookeeperPassword : fabricService.getZookeeperPassword()).jvmOpts(jvmOpts).environmentalVariable(environmentalVariables).version(version).withUser(newUser, newUserPassword, newUserRole).profiles(getProfileNames()).dataStoreProperties(getDataStoreProperties()).uploadDistribution(!distributionUploadDisable);
    if (path != null && !path.isEmpty()) {
        builder.path(path);
    }
    CreateContainerMetadata[] metadatas = fabricService.createContainers(builder.build(), new PrintStreamCreationStateListener(System.out));
    if (isEnsembleServer && metadatas != null && metadatas.length > 0 && metadatas[0].isSuccess()) {
        ShellUtils.storeZookeeperPassword(session, metadatas[0].getCreateOptions().getZookeeperPassword());
    }
    // display containers
    displayContainers(metadatas);
    return null;
}
Also used : PrintStreamCreationStateListener(io.fabric8.internal.PrintStreamCreationStateListener) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateJCloudsContainerOptions(io.fabric8.service.jclouds.CreateJCloudsContainerOptions)

Example 13 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project fabric8 by jboss-fuse.

the class FabricDiscovery method addingService.

@Override
public CuratorFramework addingService(ServiceReference<CuratorFramework> reference) {
    CuratorFramework curator = context.getService(reference);
    try {
        logger.debug("CuratorFramework found, starting group");
        GroupFactory factory = new ZooKeeperGroupFactory(curator);
        singleton = factory.createGroup("/fabric/registry/clusters/elasticsearch/" + clusterName.value(), ESNode.class);
        singleton.add(this);
        singleton.update(new ESNode(clusterName.value(), localNode, false));
        singleton.start();
    } catch (Exception e) {
        LOG.error("Error starting group", e);
    }
    return curator;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) GroupFactory(io.fabric8.groups.GroupFactory) ZooKeeperGroupFactory(io.fabric8.groups.internal.ZooKeeperGroupFactory) ZooKeeperGroupFactory(io.fabric8.groups.internal.ZooKeeperGroupFactory) ElasticsearchException(org.elasticsearch.ElasticsearchException) ElasticsearchIllegalStateException(org.elasticsearch.ElasticsearchIllegalStateException) IOException(java.io.IOException)

Example 14 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project fabric8 by jboss-fuse.

the class ServiceFactoryTest method testDiscoveryOnRestartCurator.

@Test
public void testDiscoveryOnRestartCurator() throws Exception {
    underTest = new ActiveMQServiceFactory();
    underTest.curator = curator;
    Properties props = new Properties();
    props.put("config", "amq.xml");
    props.put("broker-name", "amq");
    props.put("group", "amq");
    props.put("connectors", "openwire");
    props.put("openwire-port", "0");
    props.put("container.ip", "localhost");
    underTest.updated("b", props);
    final AtomicReference<CuratorFramework> curatorFrameworkAtomicReference = new AtomicReference<>(curator);
    OsgiFabricDiscoveryAgent osgiFabricDiscoveryAgent = new OsgiFabricDiscoveryAgent(new BundleContext() {

        @Override
        public String getProperty(String s) {
            return null;
        }

        @Override
        public Bundle getBundle() {
            return null;
        }

        @Override
        public Bundle installBundle(String s, InputStream inputStream) throws BundleException {
            return null;
        }

        @Override
        public Bundle installBundle(String s) throws BundleException {
            return null;
        }

        @Override
        public Bundle getBundle(long l) {
            return null;
        }

        @Override
        public Bundle[] getBundles() {
            return new Bundle[0];
        }

        @Override
        public void addServiceListener(ServiceListener serviceListener, String s) throws InvalidSyntaxException {
        }

        @Override
        public void addServiceListener(ServiceListener serviceListener) {
        }

        @Override
        public void removeServiceListener(ServiceListener serviceListener) {
        }

        @Override
        public void addBundleListener(BundleListener bundleListener) {
        }

        @Override
        public void removeBundleListener(BundleListener bundleListener) {
        }

        @Override
        public void addFrameworkListener(FrameworkListener frameworkListener) {
        }

        @Override
        public void removeFrameworkListener(FrameworkListener frameworkListener) {
        }

        @Override
        public ServiceRegistration<?> registerService(String[] strings, Object o, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public ServiceRegistration<?> registerService(String s, Object o, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public <S> ServiceRegistration<S> registerService(Class<S> aClass, S s, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public ServiceReference<?>[] getServiceReferences(String s, String s1) throws InvalidSyntaxException {
            return new ServiceReference<?>[0];
        }

        @Override
        public ServiceReference<?>[] getAllServiceReferences(String s, String s1) throws InvalidSyntaxException {
            return new ServiceReference<?>[0];
        }

        @Override
        public ServiceReference<?> getServiceReference(String s) {
            return null;
        }

        @Override
        public <S> ServiceReference<S> getServiceReference(Class<S> aClass) {
            return null;
        }

        @Override
        public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> aClass, String s) throws InvalidSyntaxException {
            return null;
        }

        @Override
        public <S> S getService(ServiceReference<S> serviceReference) {
            return (S) curatorFrameworkAtomicReference.get();
        }

        @Override
        public boolean ungetService(ServiceReference<?> serviceReference) {
            return false;
        }

        @Override
        public File getDataFile(String s) {
            return null;
        }

        @Override
        public Filter createFilter(String s) throws InvalidSyntaxException {
            return null;
        }

        @Override
        public Bundle getBundle(String s) {
            return null;
        }
    });
    final LinkedBlockingQueue<DiscoveryEvent> discoveryEvents = new LinkedBlockingQueue<DiscoveryEvent>(10);
    osgiFabricDiscoveryAgent.setDiscoveryListener(new DiscoveryListener() {

        @Override
        public void onServiceAdd(DiscoveryEvent discoveryEvent) {
            discoveryEvents.offer(discoveryEvent);
        }

        @Override
        public void onServiceRemove(DiscoveryEvent discoveryEvent) {
        }
    });
    // will call into dummy bundle and get curator
    osgiFabricDiscoveryAgent.addingService(null);
    osgiFabricDiscoveryAgent.setGroupName("amq");
    osgiFabricDiscoveryAgent.start();
    DiscoveryEvent event = discoveryEvents.poll(5, TimeUnit.SECONDS);
    LOG.info("event: " + event);
    assertNotNull("got added service", event);
    underTest.deleted("b");
    // swap curator ref
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).sessionTimeoutMs(15000).retryPolicy(new RetryNTimes(5000, 1000));
    curator = builder.build();
    LOG.debug("Starting new curator " + curator);
    curator.start();
    curatorFrameworkAtomicReference.get().close();
    curatorFrameworkAtomicReference.set(curator);
    // will call into dummy bundle and get new curator ref
    osgiFabricDiscoveryAgent.addingService(null);
    // start broker again
    underTest.curator = curator;
    underTest.updated("b", props);
    event = discoveryEvents.poll(5, TimeUnit.SECONDS);
    LOG.info("new event: " + event);
    assertNotNull("got newly added service", event);
    underTest.deleted("b");
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) DiscoveryEvent(org.apache.activemq.command.DiscoveryEvent) Properties(java.util.Properties) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryNTimes(org.apache.curator.retry.RetryNTimes) InputStream(java.io.InputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) OsgiFabricDiscoveryAgent(io.fabric8.mq.fabric.discovery.OsgiFabricDiscoveryAgent) Collection(java.util.Collection) File(java.io.File) DiscoveryListener(org.apache.activemq.transport.discovery.DiscoveryListener) Test(org.junit.Test)

Example 15 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project fabric8 by jboss-fuse.

the class GatewayServiceTreeCache method treeCacheEvent.

protected void treeCacheEvent(PathChildrenCacheEvent event) {
    ChildData childData = event.getData();
    if (childData == null) {
        return;
    }
    String path = childData.getPath();
    LOG.trace("Event {} on path {}", event.getType().toString(), path);
    PathChildrenCacheEvent.Type type = event.getType();
    byte[] data = childData.getData();
    if (data == null || data.length == 0 || path == null) {
        return;
    }
    if (path.startsWith(zkPath)) {
        path = path.substring(zkPath.length());
    }
    List<String> split = Strings.splitAndTrimAsList(path, "/");
    // Lets just use the group name as the service path.
    path = split.get(0);
    String zNode = split.get(1);
    boolean remove = false;
    switch(type) {
        case CHILD_ADDED:
        case CHILD_UPDATED:
            break;
        case CHILD_REMOVED:
            remove = true;
            break;
        default:
            return;
    }
    ServiceDTO dto = null;
    try {
        dto = mapper.readValue(data, ServiceDTO.class);
        expandPropertyResolvers(dto);
        dto.setContainer(dto.getContainer() + "_zNode_" + zNode);
        if (remove) {
            LOG.info("Removed gateway service: " + path + ": " + dto);
            serviceMap.serviceRemoved(path, dto);
        } else {
            LOG.info("Updated gateway service: " + path + ": " + dto);
            serviceMap.serviceUpdated(path, dto);
        }
    } catch (IOException e) {
        LOG.warn("Failed to parse the JSON: " + new String(data) + ". Reason: " + e, e);
    } catch (URISyntaxException e) {
        LOG.warn("Failed to update URI for dto: " + dto + ", .Reason: " + e, e);
    }
}
Also used : PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) ChildData(org.apache.curator.framework.recipes.cache.ChildData) ServiceDTO(io.fabric8.gateway.ServiceDTO) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Aggregations

Test (org.junit.Test)19 ArrayList (java.util.ArrayList)14 CuratorFramework (org.apache.curator.framework.CuratorFramework)12 IOException (java.io.IOException)11 Map (java.util.Map)11 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)10 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)10 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)8 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 Pod (io.fabric8.kubernetes.api.model.Pod)8 KafkaUser (io.strimzi.api.kafka.model.KafkaUser)8 HashMap (java.util.HashMap)8 List (java.util.List)8 RetryNTimes (org.apache.curator.retry.RetryNTimes)8 Tag (org.junit.jupiter.api.Tag)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)7 File (java.io.File)7 Collectors (java.util.stream.Collectors)7 APIGroup (io.fabric8.kubernetes.api.model.APIGroup)6