Java Code Examples for org.apache.brooklyn.util.core.config.ConfigBag#newInstanceCopying()

The following examples show how to use org.apache.brooklyn.util.core.config.ConfigBag#newInstanceCopying() . 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: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void logAvailableTemplates(ConfigBag config) {
    LOG.info("Loading available images at "+this+" for reference...");
    ConfigBag m1 = ConfigBag.newInstanceCopying(config);
    if (m1.containsKey(IMAGE_ID)) {
        // if caller specified an image ID, remove that, but don't apply default filters
        m1.remove(IMAGE_ID);
        // TODO use key
        m1.putStringKey("anyOwner", true);
    }
    ComputeService computeServiceLessRestrictive = getComputeService(m1);
    Set<? extends Image> imgs = computeServiceLessRestrictive.listImages();
    LOG.info(""+imgs.size()+" available images at "+this);
    for (Image img: imgs) {
        LOG.info(" Image: "+img);
    }

    Set<? extends Hardware> profiles = computeServiceLessRestrictive.listHardwareProfiles();
    LOG.info(""+profiles.size()+" available profiles at "+this);
    for (Hardware profile: profiles) {
        LOG.info(" Profile: "+profile);
    }

    Set<? extends org.jclouds.domain.Location> assignableLocations = computeServiceLessRestrictive.listAssignableLocations();
    LOG.info(""+assignableLocations.size()+" available locations at "+this);
    for (org.jclouds.domain.Location assignableLocation: assignableLocations) {
        LOG.info(" Location: "+assignableLocation);
    }
}
 
Example 2
Source File: BrooklynComponentTemplateResolver.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private BrooklynComponentTemplateResolver(BrooklynClassLoadingContext loader, ConfigBag attrs, AbstractResource optionalTemplate, String type) {
    this.loader = checkNotNull(loader, "loader");
    this.mgmt = loader.getManagementContext();
    this.attrs = ConfigBag.newInstanceCopying(attrs);
    this.template = Maybe.fromNullable(optionalTemplate);
    this.yamlLoader = new BrooklynYamlTypeInstantiator.Factory(loader, this);
    this.type = checkNotNull(type, "type");
    this.serviceSpecResolver = new CampServiceSpecResolver(mgmt, getServiceTypeResolverOverrides());
}
 
Example 3
Source File: BrooklynNodeImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void queueShutdownTask() {
    ConfigBag stopParameters = BrooklynTaskTags.getCurrentEffectorParameters();
    ConfigBag shutdownParameters;
    if (stopParameters != null) {
        shutdownParameters = ConfigBag.newInstanceCopying(stopParameters);
    } else {
        shutdownParameters = ConfigBag.newInstance();
    }
    shutdownParameters.putIfAbsent(ShutdownEffector.REQUEST_TIMEOUT, Duration.ONE_MINUTE);
    shutdownParameters.putIfAbsent(ShutdownEffector.FORCE_SHUTDOWN_ON_ERROR, Boolean.TRUE);
    TaskAdaptable<Void> shutdownTask = Effectors.invocation(this, SHUTDOWN, shutdownParameters);
    //Mark inessential so that even if it fails the process stop task will run afterwards to clean up.
    TaskTags.markInessential(shutdownTask);
    DynamicTasks.queue(shutdownTask);
}
 
Example 4
Source File: BrooklynNodeImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Void call(ConfigBag parameters) {
    Duration timeout = parameters.get(TIMEOUT);

    ConfigBag stopParameters = ConfigBag.newInstanceCopying(parameters);
    stopParameters.put(ShutdownEffector.STOP_APPS_FIRST, Boolean.FALSE);
    stopParameters.putIfAbsent(ShutdownEffector.SHUTDOWN_TIMEOUT, timeout);
    stopParameters.putIfAbsent(ShutdownEffector.REQUEST_TIMEOUT, timeout);
    DynamicTasks.queue(Effectors.invocation(entity(), STOP, stopParameters)).asTask().getUnchecked();
    return null;
}
 
Example 5
Source File: BrooklynNodeImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Void call(ConfigBag parameters) {
    Duration timeout = parameters.get(TIMEOUT);

    ConfigBag stopParameters = ConfigBag.newInstanceCopying(parameters);
    stopParameters.put(ShutdownEffector.STOP_APPS_FIRST, Boolean.TRUE);
    stopParameters.putIfAbsent(ShutdownEffector.SHUTDOWN_TIMEOUT, timeout);
    stopParameters.putIfAbsent(ShutdownEffector.REQUEST_TIMEOUT, timeout);
    DynamicTasks.queue(Effectors.invocation(entity(), STOP, stopParameters)).asTask().getUnchecked();
    return null;
}
 
Example 6
Source File: ProcessTaskWrapper.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** for overriding */
protected ConfigBag getConfigForRunning() {
    ConfigBag config = ConfigBag.newInstanceCopying(ProcessTaskWrapper.this.config);
    if (stdout!=null) config.put(ShellTool.PROP_OUT_STREAM, stdout);
    if (stderr!=null) config.put(ShellTool.PROP_ERR_STREAM, stderr);
    
    if (!config.containsKey(ShellTool.PROP_NO_EXTRA_OUTPUT))
        // by default no extra output (so things like cat, etc work as expected)
        config.put(ShellTool.PROP_NO_EXTRA_OUTPUT, true);

    if (runAsRoot)
        config.put(ShellTool.PROP_RUN_AS_ROOT, true);
    return config;
}
 
Example 7
Source File: AddEffector.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** returns a ConfigBag containing the merger of the supplied parameters with default values on the effector-defined parameters */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static ConfigBag getMergedParams(Effector<?> eff, ConfigBag params) {
    ConfigBag result = ConfigBag.newInstanceCopying(params);
    for (ParameterType<?> param: eff.getParameters()) {
        ConfigKey key = Effectors.asConfigKey(param);
        if (!result.containsKey(key))
            result.configure(key, params.get(key));
    }
    return result;
}
 
Example 8
Source File: BrooklynNodeUpgradeEffectorBody.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
public Void call(ConfigBag parametersO) {
    if (!isPersistenceModeEnabled(entity())) {
        // would could try a `forcePersistNow`, but that's sloppy; 
        // for now, require HA/persistence for upgrading
        DynamicTasks.queue( Tasks.warning("Check persistence", 
            new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
            + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
    }

    final ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);

    /*
     * all parameters are passed to children, apart from EXTRA_CONFIG
     * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
     * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)  
     */
    if (parameters.containsKey(EXTRA_CONFIG)) {
        Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
        parameters.remove(EXTRA_CONFIG);
        parameters.putAll(extra);
    }
    log.debug(this+" upgrading, using "+parameters);
    
    final String bkName;
    boolean doDryRunFirst = parameters.get(DO_DRY_RUN_FIRST);
    if(doDryRunFirst) {
        bkName = dryRunUpdate(parameters);
    } else {
        bkName = "direct-"+Identifiers.makeRandomId(4);
    }
    
    // Stop running instance
    DynamicTasks.queue(Tasks.builder().displayName("shutdown node")
            .add(Effectors.invocation(entity(), BrooklynNode.STOP_NODE_BUT_LEAVE_APPS, ImmutableMap.of(StopSoftwareParameters.STOP_MACHINE_MODE, StopMode.NEVER)))
            .build());

    // backup old files
    DynamicTasks.queue(Tasks.builder().displayName("backup old version").body(new Runnable() {
        @Override
        public void run() {
            String runDir = entity().getAttribute(SoftwareProcess.RUN_DIR);
            String bkDir = Urls.mergePaths(runDir, "..", Urls.getBasename(runDir)+"-backups", bkName);
            log.debug(this+" storing backup of previous version in "+bkDir);
            DynamicTasks.queue(SshEffectorTasks.ssh(
                "cd "+runDir,
                "mkdir -p "+bkDir,
                "mv * "+bkDir
                // By removing the run dir of the entity we force it to go through
                // the customize step again on start and re-generate local-brooklyn.properties.
                ).summary("move files"));
        }
    }).build());
    
    // Reconfigure entity
    DynamicTasks.queue(Tasks.builder().displayName("reconfigure").body(new Runnable() {
        @Override
        public void run() {
            DynamicTasks.waitForLast();
            entity().sensors().set(SoftwareProcess.INSTALL_DIR, (String)null);
            entity().config().set(SoftwareProcess.INSTALL_UNIQUE_LABEL, (String)null);
            entity().config().putAll(parameters.getAllConfig());
            entity().sensors().set(BrooklynNode.DOWNLOAD_URL, entity().getConfig(DOWNLOAD_URL));

            // Setting SUGGESTED_VERSION will result in an new empty INSTALL_FOLDER, but clear it
            // just in case the user specified already installed version.
            ((BrooklynNodeDriver)((DriverDependentEntity<?>)entity()).getDriver()).clearInstallDir();
        }
    }).build());
    
    // Start this entity, running the new version.
    // This will download and install the new dist (if not already done by the dry run node).
    DynamicTasks.queue(Effectors.invocation(entity(), BrooklynNode.START, ConfigBag.EMPTY));

    return null;
}