Search in sources :

Example 36 with Result

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

the class ComponentConfigurer method configure.

@Override
public <T> Map<String, ?> configure(final Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
    assertValid();
    Map<String, Object> result = new HashMap<>();
    final PropertiesProvider runtimeProperties = new PropertiesProvider() {

        @Override
        public Object getProperty(String key) {
            return bundleContext.getProperty(key);
        }

        @Override
        public Object getRequiredProperty(String key) {
            String value = bundleContext.getProperty(key);
            IllegalStateAssertion.assertNotNull(value, "Cannot obtain property: " + key);
            return value;
        }

        @Override
        public Object getProperty(String key, Object defaultValue) {
            String value = bundleContext.getProperty(key);
            return value != null ? value : defaultValue;
        }
    };
    final PropertiesProvider configurationProvider = new MapPropertiesProvider((Map<String, Object>) configuration);
    final PropertiesProvider[] propertiesProviders = new PropertiesProvider[] { configurationProvider, runtimeProperties };
    PropertiesProvider provider = new SubstitutionPropertiesProvider(propertiesProviders);
    for (Map.Entry<String, ?> entry : configuration.entrySet()) {
        String key = entry.getKey();
        Object value = provider.getProperty(key);
        result.put(key, value);
    }
    ConfigInjection.applyConfiguration(result, target, ignorePrefix);
    return result;
}
Also used : MapPropertiesProvider(io.fabric8.api.gravia.MapPropertiesProvider) PropertiesProvider(io.fabric8.api.gravia.PropertiesProvider) SubstitutionPropertiesProvider(io.fabric8.api.gravia.SubstitutionPropertiesProvider) SubstitutionPropertiesProvider(io.fabric8.api.gravia.SubstitutionPropertiesProvider) MapPropertiesProvider(io.fabric8.api.gravia.MapPropertiesProvider) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with Result

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

the class FabricManager method getJvmOpts.

@Override
public /**
 * Returns configured jvmOpts only for (local and remote) Karaf containers.
 */
String getJvmOpts(String containerName) {
    String result = "";
    Container container = fabricService.getContainer(containerName);
    CreateContainerBasicMetadata metadata = (CreateContainerBasicMetadata) container.getMetadata();
    if (metadata == null) {
        return "Inapplicable";
    }
    switch(metadata.getCreateOptions().getProviderType()) {
        case "child":
        case "ssh":
            CreateContainerOptions createOptions = metadata.getCreateOptions();
            result = createOptions.getJvmOpts();
            break;
        default:
            result = "Inapplicable";
    }
    return result;
}
Also used : Container(io.fabric8.api.Container) CreateContainerOptions(io.fabric8.api.CreateContainerOptions) CreateContainerBasicMetadata(io.fabric8.api.CreateContainerBasicMetadata)

Example 38 with Result

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

the class ContainerLifecycleCommandsTest method testStopGlobMatchingContainers.

@Test
public void testStopGlobMatchingContainers() throws Exception {
    // should stop c2 once
    // should not touch d1
    containers("c*", "c2");
    ContainerImpl c1 = newContainer("c1");
    ContainerImpl c2 = newContainer("c2");
    ContainerImpl c3 = newContainer("c3");
    ContainerImpl d1 = newContainer("d1");
    expect(this.fabricService.getContainers()).andReturn(new Container[] { c1, c3, c2, d1 }).once();
    expect(this.fabricService.adapt(CuratorFramework.class)).andReturn(this.curatorFramework);
    expect(this.fabricService.getContainers()).andReturn(new Container[] { c1, c3, c2, d1 }).once();
    this.fabricService.stopContainer(c1, false);
    expect(this.fabricService.adapt(CuratorFramework.class)).andReturn(this.curatorFramework);
    expect(this.fabricService.getContainers()).andReturn(new Container[] { c1, c3, c2, d1 }).once();
    this.fabricService.stopContainer(c3, false);
    expect(this.fabricService.adapt(CuratorFramework.class)).andReturn(this.curatorFramework);
    expect(this.fabricService.getContainers()).andReturn(new Container[] { c1, c3, c2, d1 }).once();
    this.fabricService.stopContainer(c2, false);
    replay(this.fabricService, this.commandSession);
    this.stop.execute(this.commandSession);
    verify(this.fabricService);
    String result = new String(this.result.toByteArray());
    assertThat(result.contains("Container 'c1' stopped successfully."), is(true));
    assertThat(result.contains("Container 'c2' stopped successfully."), is(true));
    assertThat(result.contains("Container 'c3' stopped successfully."), is(true));
}
Also used : Container(io.fabric8.api.Container) ContainerImpl(io.fabric8.internal.ContainerImpl) Test(org.junit.Test)

Example 39 with Result

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

the class JMXCommandActionSupport method asResults.

protected List<JMXResult> asResults(String path, List<String> responses, Class<?> resultClass) throws Exception {
    ObjectMapper mapper = getObjectMapper();
    List<JMXResult> results = new LinkedList<>();
    for (String responsePath : responses) {
        byte[] bytes = curator.getData().forPath(path + "/" + responsePath);
        String response = PublicStringSerializer.deserialize(bytes);
        JMXResult result = mapper.readValue(response, JMXResult.class);
        if (result.getResponse() instanceof String) {
            try {
                result.setResponse(mapper.readValue((String) result.getResponse(), resultClass));
            } catch (JsonMappingException | IllegalArgumentException ignore) {
                continue;
            }
        }
        results.add(result);
    }
    mapper.getTypeFactory().clearCache();
    return results;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JMXResult(io.fabric8.api.commands.JMXResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedList(java.util.LinkedList)

Example 40 with Result

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

the class BaseRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
    for (Requirement requirement : requirements) {
        CapabilitySet set = capSets.get(requirement.getNamespace());
        if (set != null) {
            SimpleFilter sf;
            if (requirement instanceof RequirementImpl) {
                sf = ((RequirementImpl) requirement).getFilter();
            } else {
                String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
                sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
            }
            result.put(requirement, set.match(sf, true));
        } else {
            result.put(requirement, Collections.<Capability>emptyList());
        }
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) RequirementImpl(io.fabric8.agent.resolver.RequirementImpl) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter) Collection(java.util.Collection) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet)

Aggregations

Test (org.junit.Test)104 Expectations (mockit.Expectations)49 HashMap (java.util.HashMap)32 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 File (java.io.File)21 GitContext (io.fabric8.api.GitContext)20 IOException (java.io.IOException)20 Exchange (org.apache.camel.Exchange)20 Processor (org.apache.camel.Processor)20 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)17 Probe (io.fabric8.kubernetes.api.model.Probe)16 PatchResult (io.fabric8.patch.management.PatchResult)13 Properties (java.util.Properties)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)11 Patch (io.fabric8.patch.management.Patch)11 PatchException (io.fabric8.patch.management.PatchException)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 TreeMap (java.util.TreeMap)10