Java Code Examples for org.apache.brooklyn.util.collections.MutableMap#putAll()

The following examples show how to use org.apache.brooklyn.util.collections.MutableMap#putAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OsgiConfigLoader.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> load() {
    if (configAdmin == null) {
        LOG.warn("No OSGi configuration-admin available - cannot load {}.cfg", propertiesPath);
        return ImmutableMap.of();
    }

    String filter = '(' + Constants.SERVICE_PID + '=' + propertiesPath + ')';
    Configuration[] configs;

    try {
        configs = configAdmin.listConfigurations(filter);
    } catch (InvalidSyntaxException | IOException e) {
        LOG.info("Cannot list OSGi configurations");
        throw Exceptions.propagate(e);
    }

    final MutableMap<String, String> map = MutableMap.of();
    if (configs != null) {
        for (Configuration config : configs) {
            LOG.debug("Reading OSGi configuration from {}; bundleLocation={}", config.getPid(), config.getBundleLocation());
            map.putAll(dictToMap(config.getProperties()));
        }
    } else {
        LOG.info("No OSGi configuration found for {}.cfg", propertiesPath);
    }

    return map;
}
 
Example 2
Source File: BrooklynYamlTypeInstantiator.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** finds the map of config for the type specified;
 * currently only gets <code>brooklyn.config</code>, returning empty map if none,
 * but TODO in future should support recognized flags and config keys (those declared on the type),
 * incorporating code in {@link BrooklynEntityMatcher}.
 */
@SuppressWarnings("unchecked")
@Nonnull
public Map<String,?> getConfigMap() {
    MutableMap<String,Object> result = MutableMap.of();
    Object bc = data.getStringKey(BrooklynCampReservedKeys.BROOKLYN_CONFIG);
    if (bc!=null) {
        if (bc instanceof Map)
            result.putAll((Map<? extends String, ?>) bc);
        else
            throw new IllegalArgumentException("brooklyn.config key in "+factory.contextForLogging+" should be a map, not "+bc.getClass()+" ("+bc+")");
    }
    return result; 
}
 
Example 3
Source File: RebindContextImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String,BrooklynObject> getAllBrooklynObjects() {
    MutableMap<String,BrooklynObject> result = MutableMap.of();
    result.putAll(locations);
    result.putAll(entities);
    result.putAll(policies);
    result.putAll(enrichers);
    result.putAll(feeds);
    result.putAll(catalogItems);
    result.putAll(bundles);
    return result.asUnmodifiable();
}
 
Example 4
Source File: SshCommandEffector.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public SshEffectorTaskFactory<String> makePartialTaskFactory(ConfigBag params, Entity entity) {
    String sshCommand = SshCommandSensor.makeCommandExecutingInDirectory(command, executionDir, entity);

    MutableMap<String, Object> env = MutableMap.of();

    // Set all declared parameters, including default values
    for (ParameterType<?> param : effector.getParameters()) {
        env.addIfNotNull(param.getName(), params.get(Effectors.asConfigKey(param)));
    }

    // Set things from the entity's defined shell environment, if applicable
    env.putAll(entity.config().get(BrooklynConfigKeys.SHELL_ENVIRONMENT));

    // Set the parameters we've been passed. This will repeat declared parameters but to no harm,
    // it may pick up additional values (could be a flag defining whether this is permitted or not.)
    // Make sure we do not include the shell.env here again, by filtering it out.
    env.putAll(Maps.filterKeys(params.getAllConfig(), Predicates.not(Predicates.equalTo(EFFECTOR_SHELL_ENVIRONMENT.getName()))));

    // Add the shell environment entries from the effector configuration
    if (shellEnv != null) env.putAll(shellEnv);

    // Add the shell environment entries from our invocation
    Map<String, Object> effectorEnv = params.get(EFFECTOR_SHELL_ENVIRONMENT);
    if (effectorEnv != null) env.putAll(effectorEnv);
    
    // Try to resolve the configuration in the env Map
    try {
        env = MutableMap.copyOf(resolveEnv(env));
    } catch (InterruptedException | ExecutionException e) {
        Exceptions.propagateIfFatal(e);
    }

    // Execute the effector with the serialized environment strings
    ShellEnvironmentSerializer serializer = new ShellEnvironmentSerializer(entity().getManagementContext());

    return SshEffectorTasks.ssh(sshCommand)
            .requiringZeroAndReturningStdout()
            .environmentVariables(serializer.serialize(env));
}
 
Example 5
Source File: BrooklynEntityMatcher.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
public boolean apply(Object deploymentPlanItem, AssemblyTemplateConstructor atc) {
    if (!(deploymentPlanItem instanceof Service)) return false;
    
    String type = lookupType(deploymentPlanItem);
    if (type==null) return false;

    log.trace("Item {} being instantiated with {}", deploymentPlanItem, type);

    Object old = atc.getInstantiator();
    if (old!=null && !old.equals(BrooklynAssemblyTemplateInstantiator.class)) {
        log.warn("Can't mix Brooklyn entities with non-Brooklyn entities (at present): "+old);
        return false;
    }

    // TODO should we build up a new type, BrooklynEntityComponentTemplate here
    // complete w EntitySpec -- ie merge w BrooklynComponentTemplateResolver ?
    
    Builder<? extends PlatformComponentTemplate> builder = PlatformComponentTemplate.builder();
    builder.type( type.indexOf(':')==-1 ? "brooklyn:"+type : type );
    
    // currently instantiator must be brooklyn at the ATC level
    // optionally would be nice to support multiple/mixed instantiators, 
    // ie at the component level, perhaps with the first one responsible for building the app
    atc.instantiator(BrooklynAssemblyTemplateInstantiator.class);

    String name = ((Service)deploymentPlanItem).getName();
    if (!Strings.isBlank(name)) builder.name(name);
    
    // configuration
    Map<String, Object> attrs = MutableMap.copyOf( ((Service)deploymentPlanItem).getCustomAttributes() );

    if (attrs.containsKey("id"))
        builder.customAttribute("planId", attrs.remove("id"));

    Object location = attrs.remove("location");
    if (location!=null)
        builder.customAttribute("location", location);
    Object locations = attrs.remove("locations");
    if (locations!=null)
        builder.customAttribute("locations", locations);
    Object iconUrl = attrs.remove(BrooklynConfigKeys.ICON_URL.getName());
    if (iconUrl!=null)
        builder.customAttribute(BrooklynConfigKeys.ICON_URL.getName(), iconUrl);

    MutableMap<Object, Object> brooklynFlags = MutableMap.of();
    Object origBrooklynFlags = attrs.remove(BrooklynCampReservedKeys.BROOKLYN_FLAGS);
    if (origBrooklynFlags!=null) {
        if (!(origBrooklynFlags instanceof Map))
            throw new IllegalArgumentException("brooklyn.flags must be a map of brooklyn flags");
        brooklynFlags.putAll((Map<?,?>)origBrooklynFlags);
    }

    addCustomMapAttributeIfNonNull(builder, attrs, BrooklynCampReservedKeys.BROOKLYN_CONFIG);
    addCustomListAttributeIfNonNull(builder, attrs, BrooklynCampReservedKeys.BROOKLYN_POLICIES);
    addCustomListAttributeIfNonNull(builder, attrs, BrooklynCampReservedKeys.BROOKLYN_ENRICHERS);
    addCustomListAttributeIfNonNull(builder, attrs, BrooklynCampReservedKeys.BROOKLYN_INITIALIZERS);
    addCustomListAttributeIfNonNull(builder, attrs, BrooklynCampReservedKeys.BROOKLYN_CHILDREN);
    addCustomListAttributeIfNonNull(builder, attrs, BrooklynCampReservedKeys.BROOKLYN_PARAMETERS);
    addCustomMapAttributeIfNonNull(builder, attrs, BrooklynCampReservedKeys.BROOKLYN_CATALOG);
    addCustomListAttributeIfNonNull(builder, attrs, BrooklynCampReservedKeys.BROOKLYN_TAGS);

    brooklynFlags.putAll(attrs);
    if (!brooklynFlags.isEmpty()) {
        builder.customAttribute(BrooklynCampReservedKeys.BROOKLYN_FLAGS, brooklynFlags);
    }

    atc.add(builder.build());

    return true;
}