Search in sources :

Example 36 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class CreateSsl method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Target targetUtil = habitat.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    if (!"iiop-service".equals(type) && (listenerId == null)) {
        report.setMessage(LOCAL_STRINGS.getLocalString("create.ssl.listenerid.missing", "Listener id needs to be specified"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    SslConfigHandler configHandler = habitat.getService(SslConfigHandler.class, type);
    if (configHandler != null) {
        configHandler.create(this, report);
    } else if ("jmx-connector".equals(type)) {
        addSslToJMXConnector(config, report);
    }
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport)

Example 37 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class ClusterOperationUtil method replicateCommand.

/**
 * Replicates a given command on the given list of targets, optionally gathering
 * downloaded result payloads from the instance commands into a directory.
 * <p>
 * If intermediateDownloadDir is non-null, then any files returned from
 * the instances in the payload of the HTTP response will be stored in a
 * directory tree like this:
 * <pre>
 * ${intermediateDownloadDir}/
 *     ${instanceA}/
 *         file(s) returned from instance A
 *     ${instanceB}/
 *         file(s) returned from instance B
 *     ...
 * </pre>
 * where ${instanceA}, ${instanceB}, etc. are the names of the instances to
 * which the command was replicated.  This method does no further processing
 * on the downloaded files but leaves that to the calling command.
 */
public static ActionReport.ExitCode replicateCommand(String commandName, FailurePolicy failPolicy, FailurePolicy offlinePolicy, FailurePolicy neverStartedPolicy, Collection<String> targetNames, AdminCommandContext context, ParameterMap parameters, ServiceLocator habitat, File intermediateDownloadDir) {
    ActionReport.ExitCode result = ActionReport.ExitCode.SUCCESS;
    Target targetService = habitat.getService(Target.class);
    for (String t : targetNames) {
        if (CommandTarget.DAS.isValid(habitat, t) || CommandTarget.DOMAIN.isValid(habitat, t))
            continue;
        parameters.set("target", t);
        List<Server> instances = targetService.getInstances(t);
        ActionReport.ExitCode returnValue = replicateCommand(commandName, failPolicy, offlinePolicy, neverStartedPolicy, instances, context, parameters, habitat, intermediateDownloadDir);
        if (!returnValue.equals(ActionReport.ExitCode.SUCCESS)) {
            result = returnValue;
        }
    }
    return result;
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Server(com.sun.enterprise.config.serverbeans.Server) ActionReport(org.glassfish.api.ActionReport)

Example 38 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class DeleteResourceRef method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        deleteResourceRef();
        if (refContainer instanceof Cluster) {
            // delete ResourceRef for all instances of Cluster
            Target tgt = habitat.getService(Target.class);
            List<Server> instances = tgt.getInstances(target);
            for (Server svr : instances) {
                svr.deleteResourceRef(refName);
            }
        }
        if (refContainer instanceof DeploymentGroup) {
            // delete ResourceRef for all instances of Cluster
            Target tgt = habitat.getService(Target.class);
            List<Server> instances = tgt.getInstances(target);
            for (Server svr : instances) {
                svr.deleteResourceRef(refName);
            }
        }
    } catch (Exception e) {
        setFailureMessage(report, e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    report.setMessage(LOCAL_STRINGS.getLocalString("delete.resource.ref.success", "resource-ref {0} deleted successfully from target {1}.", refName, target));
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ActionReport(org.glassfish.api.ActionReport) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 39 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class CreateResourceRef method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (isResourceRefAlreadyPresent()) {
        report.setMessage(LOCAL_STRINGS.getLocalString("create.resource.ref.existsAlready", "Resource ref {0} already exists for target {1}", refName, target));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        createResourceRef();
        // create new ResourceRef for all instances of Cluster, if it's a cluster
        if (refContainer instanceof Cluster && isElegibleResource(refName)) {
            Target tgt = locator.getService(Target.class);
            List<Server> instances = tgt.getInstances(target);
            for (Server server : instances) {
                server.createResourceRef(enabled.toString(), refName);
            }
        }
        // create new ResourceRef for all instances of DeploymentGroup, if it's a DeploymentGroup
        if (refContainer instanceof DeploymentGroup && isElegibleResource(refName)) {
            DeploymentGroup deploymentGroup = (DeploymentGroup) refContainer;
            for (Server server : deploymentGroup.getInstances()) {
                if (server.getResourceRef(refName) == null) {
                    server.createResourceRef(enabled.toString(), refName);
                }
            }
        }
        ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
        report.setMessage(LOCAL_STRINGS.getLocalString("create.resource.ref.success", "resource-ref {0} created successfully.", refName));
        report.setActionExitCode(ec);
    } catch (TransactionFailure tfe) {
        report.setMessage(LOCAL_STRINGS.getLocalString("create.resource.ref.failed", "Resource ref {0} creation failed", refName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ActionReport(org.glassfish.api.ActionReport) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Aggregations

Target (org.glassfish.internal.api.Target)39 CommandTarget (org.glassfish.config.support.CommandTarget)35 Config (com.sun.enterprise.config.serverbeans.Config)32 ActionReport (org.glassfish.api.ActionReport)32 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 PropertyVetoException (java.beans.PropertyVetoException)11 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)11 Protocols (org.glassfish.grizzly.config.dom.Protocols)10 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)9 List (java.util.List)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 HttpService (com.sun.enterprise.config.serverbeans.HttpService)4 SystemPropertyConstants (com.sun.enterprise.util.SystemPropertyConstants)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 Logger (java.util.logging.Logger)3 Inject (javax.inject.Inject)3 I18n (org.glassfish.api.I18n)3 Param (org.glassfish.api.Param)3