Search in sources :

Example 6 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentFieldActivationTest method test_field_activator_failure.

@Test
public void test_field_activator_failure() throws Exception {
    final String componentname = "FieldActivatorComponent.unsatisfied";
    ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
    assertEquals(1, cc.description.activationFields.length);
    assertTrue(Arrays.asList(cc.description.activationFields).contains("foo"));
    // we get the component, although the field does not exist!
    FieldActivatorComponent cmp = this.getServiceFromConfiguration(cc, FieldActivatorComponent.class);
    assertTrue(cmp.isActivateCalled());
    assertTrue(cmp.setBeforeActivate().isEmpty());
    assertEquals(4, cmp.notSetBeforeActivate().size());
    assertNull(cmp.additionalError());
    disableAndCheck(cc);
}
Also used : FieldActivatorComponent(org.apache.felix.scr.integration.components.FieldActivatorComponent) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Test(org.junit.Test)

Example 7 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentCommands method format.

CharSequence format(ComponentDescriptionDTO dto, int level) throws Exception {
    final StringBuilder builder = new StringBuilder();
    // Get the child ComponentConfigurationDTOs and sort by id field.
    final List<ComponentConfigurationDTO> children;
    Collection<ComponentConfigurationDTO> childrenTmp = scr.getComponentConfigurationDTOs(dto);
    if (childrenTmp == null) {
        children = Collections.emptyList();
    } else {
        children = new ArrayList<>(childrenTmp);
        Collections.sort(children, configDtoComparator);
    }
    switch(level) {
        case Converter.LINE:
            builder.append(MessageFormat.format("{0} in bundle {1} ({2}:{3}) {4}, {5,choice,0#0 instances|1#1 instance|1<{5} instances}.", dto.name, dto.bundle.id, dto.bundle.symbolicName, dto.bundle.version, dto.defaultEnabled ? "enabled" : "disabled", children.size()));
            for (ComponentConfigurationDTO child : children) builder.append("\n").append(INDENT_2).append(format(child, Converter.LINE));
            break;
        case Converter.INSPECT:
            printComponentDescriptionAndConfigs(dto, children.toArray(new ComponentConfigurationDTO[0]), builder);
            break;
        case Converter.PART:
            break;
    }
    return builder;
}
Also used : ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 8 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentConfigurationPrinter method printComponentsJson.

private final void printComponentsJson(final PrintWriter pw, final List<ComponentDescriptionDTO> disabled, final List<ComponentConfigurationDTO> configurations, final boolean details) throws IOException {
    final JSONWriter jw = new JSONWriter(pw);
    jw.object();
    // $NON-NLS-1$
    jw.key("components");
    jw.array();
    // render disabled descriptions
    for (final ComponentDescriptionDTO cd : disabled) {
        plugin.component(jw, cd, null, details);
    }
    // render configurations
    for (final ComponentConfigurationDTO cfg : configurations) {
        plugin.component(jw, cfg.description, cfg, details);
    }
    jw.endArray();
    jw.endObject();
}
Also used : JSONWriter(org.apache.felix.utils.json.JSONWriter) ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 9 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentConfigurationPrinter method printComponentsText.

private static final void printComponentsText(final PrintWriter pw, final List<ComponentDescriptionDTO> disabled, final List<ComponentDescriptionDTO> noConfig, final List<ComponentConfigurationDTO> configurations) {
    if (!disabled.isEmpty()) {
        pw.println(SEP);
        pw.println("Disabled components:");
        pw.println(SEP);
        for (final ComponentDescriptionDTO cd : disabled) {
            disabledComponent(pw, cd);
        }
        pw.println();
    }
    if (!noConfig.isEmpty()) {
        pw.println(SEP);
        pw.println("Components with missing configuration in Config Admin:");
        pw.println(SEP);
        for (final ComponentDescriptionDTO cd : noConfig) {
            disabledComponent(pw, cd);
        }
        pw.println();
    }
    pw.println(SEP);
    if (configurations.isEmpty()) {
        pw.println("Status: No Component Configurations");
        pw.println(SEP);
    } else {
        pw.println("Component Configurations:");
        pw.println(SEP);
        // order components by id
        TreeMap<Long, ComponentConfigurationDTO> componentMap = new TreeMap<Long, ComponentConfigurationDTO>();
        for (final ComponentConfigurationDTO cfg : configurations) {
            componentMap.put(new Long(cfg.id), cfg);
        }
        // render components
        for (final ComponentConfigurationDTO cfg : componentMap.values()) {
            component(pw, cfg);
        }
    }
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) TreeMap(java.util.TreeMap) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 10 with ComponentConfigurationDTO

use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.

the class ComponentConfigurationPrinter method print.

/**
 * @see org.apache.felix.inventory.InventoryPrinter#print(java.io.PrintWriter, org.apache.felix.inventory.Format, boolean)
 */
public void print(PrintWriter pw, Format format, boolean isZip) {
    final List<ComponentDescriptionDTO> noConfig = new ArrayList<ComponentDescriptionDTO>();
    final List<ComponentDescriptionDTO> disabled = new ArrayList<ComponentDescriptionDTO>();
    final List<ComponentConfigurationDTO> configurations = new ArrayList<ComponentConfigurationDTO>();
    final Collection<ComponentDescriptionDTO> descs = scrService.getComponentDescriptionDTOs();
    for (final ComponentDescriptionDTO d : descs) {
        if (!scrService.isComponentEnabled(d)) {
            disabled.add(d);
        } else {
            final Collection<ComponentConfigurationDTO> configs = scrService.getComponentConfigurationDTOs(d);
            if (configs.isEmpty()) {
                noConfig.add(d);
            } else {
                configurations.addAll(configs);
            }
        }
    }
    Collections.sort(configurations, Util.COMPONENT_COMPARATOR);
    if (Format.JSON.equals(format)) {
        disabled.addAll(noConfig);
        try {
            printComponentsJson(pw, disabled, configurations, isZip);
        } catch (IOException ignore) {
        // ignore
        }
    } else {
        printComponentsText(pw, disabled, noConfig, configurations);
    }
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Aggregations

ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)91 Test (org.junit.Test)63 SimpleComponent (org.apache.felix.scr.integration.components.SimpleComponent)23 SimpleServiceImpl (org.apache.felix.scr.integration.components.SimpleServiceImpl)22 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)21 A (org.apache.felix.scr.integration.components.circular.A)9 B (org.apache.felix.scr.integration.components.circular.B)9 ArrayList (java.util.ArrayList)7 Bundle (org.osgi.framework.Bundle)6 Configuration (org.osgi.service.cm.Configuration)6 ServiceReference (org.osgi.framework.ServiceReference)5 ServiceComponentRuntime (org.osgi.service.component.runtime.ServiceComponentRuntime)5 ReferenceDTO (org.osgi.service.component.runtime.dto.ReferenceDTO)4 Hashtable (java.util.Hashtable)3 ConstructorComponent (org.apache.felix.scr.integration.components.ConstructorComponent)3 FieldActivatorComponent (org.apache.felix.scr.integration.components.FieldActivatorComponent)3 UnsatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)3 TreeMap (java.util.TreeMap)2 Component (org.apache.felix.scr.Component)2 ActivatorComponent (org.apache.felix.scr.integration.components.ActivatorComponent)2