Search in sources :

Example 46 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class GetZendeskSupportConfigurationCommand method execute.

@Override
public void execute(AdminCommandContext acc) {
    Config configNode = targetUtil.getConfig(config);
    ZendeskSupportConfiguration zendeskSupportConfiguration = configNode.getExtensionByType(ZendeskSupportConfiguration.class);
    ActionReport actionReport = acc.getActionReport();
    final String[] outputHeaders = { "Enabled", "Email Address" };
    ColumnFormatter columnFormatter = new ColumnFormatter(outputHeaders);
    Object[] outputValues = { zendeskSupportConfiguration.getEnabled(), zendeskSupportConfiguration.getEmailAddress() };
    columnFormatter.addRow(outputValues);
    actionReport.appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropsMap = new HashMap<>();
    extraPropsMap.put("enabled", zendeskSupportConfiguration.getEnabled());
    extraPropsMap.put("emailAddress", zendeskSupportConfiguration.getEmailAddress());
    Properties extraProps = new Properties();
    extraProps.put("zendeskSupportConfiguration", extraPropsMap);
    actionReport.setExtraProperties(extraProps);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ZendeskSupportConfiguration(fish.payara.appserver.zendesk.config.ZendeskSupportConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 47 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class TestEmailNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    EmailNotifierConfiguration emailConfig = config.getExtensionByType(EmailNotifierConfiguration.class);
    if (jndiName == null) {
        jndiName = emailConfig.getJndiName();
    }
    if (to == null) {
        to = emailConfig.getTo();
    }
    // prepare email
    EmailNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    EmailMessageQueue queue = new EmailMessageQueue();
    queue.addMessage(new EmailMessage(event, event.getSubject(), event.getMessage()));
    EmailNotifierConfigurationExecutionOptions options = new EmailNotifierConfigurationExecutionOptions();
    options.setJndiName(jndiName);
    options.setTo(to);
    Session session;
    try {
        InitialContext initialContext = new InitialContext();
        session = (Session) initialContext.lookup(jndiName);
    } catch (NamingException ex) {
        Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, "Unable to find session" + jndiName);
        context.getActionReport().setMessage("Unable to find session: " + jndiName);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    EmailNotificationRunnable notifierRun = new EmailNotificationRunnable(queue, session, options);
    // set up logger to store result
    Logger logger = Logger.getLogger(EmailNotificationRunnable.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler(10);
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    // send message, this occurs in its own thread
    Thread notifierThread = new Thread(notifierRun, "test-email-notifier-thread");
    notifierThread.start();
    try {
        notifierThread.join();
    } catch (InterruptedException ex) {
        Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        logger.setLevel(oldLevel);
    }
    LogRecord message = bqh.poll();
    logger.removeHandler(bqh);
    if (message == null) {
        // something's gone wrong
        Logger.getLogger(TestEmailNotifier.class.getName()).log(Level.SEVERE, "Failed to send email");
        actionReport.setMessage("Failed to send email message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        if (message.getLevel() == Level.FINE) {
            actionReport.setMessage(message.getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setMessage(message.getMessage() + message.getThrown().getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) InitialContext(javax.naming.InitialContext) BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) NamingException(javax.naming.NamingException) Level(java.util.logging.Level) Session(javax.mail.Session)

Example 48 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class ListManagedThreadFactories 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
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Collection<ManagedThreadFactory> managedThreadFactories = domain.getResources().getResources(ManagedThreadFactory.class);
        List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (ManagedThreadFactory managedThreadFactory : managedThreadFactories) {
            String jndiName = managedThreadFactory.getJndiName();
            if (bindableResourcesHelper.resourceExists(jndiName, target)) {
                ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(jndiName);
                Map<String, String> resourceNameMap = new HashMap<String, String>();
                String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
                if (logicalName != null) {
                    resourceNameMap.put("logical-jndi-name", logicalName);
                }
                resourceNameMap.put("name", jndiName);
                resourcesList.add(resourceNameMap);
            }
        }
        Properties extraProperties = new Properties();
        extraProperties.put("managedThreadFactories", resourcesList);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.managed.thread.factory.failed", "List managed thread factories failed"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : DefaultResourceProxy(org.glassfish.api.naming.DefaultResourceProxy) ActionReport(org.glassfish.api.ActionReport) ManagedThreadFactory(org.glassfish.concurrent.config.ManagedThreadFactory) DefaultManagedThreadFactory(org.glassfish.concurrent.runtime.deployer.DefaultManagedThreadFactory)

Example 49 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class ListContextServices 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
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Collection<ContextService> contextServices = domain.getResources().getResources(ContextService.class);
        List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (ContextService contextService : contextServices) {
            String jndiName = contextService.getJndiName();
            if (bindableResourcesHelper.resourceExists(jndiName, target)) {
                ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(jndiName);
                Map<String, String> resourceNameMap = new HashMap<String, String>();
                String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
                if (logicalName != null) {
                    resourceNameMap.put("logical-jndi-name", logicalName);
                }
                resourceNameMap.put("name", jndiName);
                resourcesList.add(resourceNameMap);
            }
        }
        Properties extraProperties = new Properties();
        extraProperties.put("contextServices", resourcesList);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.context.service.failed", "List context services failed"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ContextService(org.glassfish.concurrent.config.ContextService) DefaultContextService(org.glassfish.concurrent.runtime.deployer.DefaultContextService) DefaultResourceProxy(org.glassfish.api.naming.DefaultResourceProxy) ActionReport(org.glassfish.api.ActionReport)

Example 50 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class CreateConnectorConnectionPool 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
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    HashMap attrList = new HashMap();
    attrList.put(ResourceConstants.RES_ADAPTER_NAME, raname);
    attrList.put(ResourceConstants.CONN_DEF_NAME, connectiondefinition);
    attrList.put(ServerTags.DESCRIPTION, description);
    attrList.put(ResourceConstants.STEADY_POOL_SIZE, steadypoolsize);
    attrList.put(ResourceConstants.MAX_POOL_SIZE, maxpoolsize);
    attrList.put(ResourceConstants.MAX_WAIT_TIME_IN_MILLIS, maxwait);
    attrList.put(ResourceConstants.POOL_SIZE_QUANTITY, poolresize);
    attrList.put(ResourceConstants.IDLE_TIME_OUT_IN_SECONDS, idletimeout);
    attrList.put(ResourceConstants.IS_CONNECTION_VALIDATION_REQUIRED, isconnectvalidatereq.toString());
    attrList.put(ResourceConstants.CONN_FAIL_ALL_CONNECTIONS, failconnection.toString());
    attrList.put(ResourceConstants.VALIDATE_ATMOST_ONCE_PERIOD_IN_SECONDS, validateatmostonceperiod);
    attrList.put(ResourceConstants.CONNECTION_LEAK_TIMEOUT_IN_SECONDS, leaktimeout);
    attrList.put(ResourceConstants.CONNECTION_LEAK_RECLAIM, leakreclaim.toString());
    attrList.put(ResourceConstants.CONNECTION_CREATION_RETRY_ATTEMPTS, creationretryattempts);
    attrList.put(ResourceConstants.CONNECTION_CREATION_RETRY_INTERVAL_IN_SECONDS, creationretryinterval);
    attrList.put(ResourceConstants.LAZY_CONNECTION_ASSOCIATION, lazyconnectionassociation.toString());
    attrList.put(ResourceConstants.LAZY_CONNECTION_ENLISTMENT, lazyconnectionenlistment.toString());
    attrList.put(ResourceConstants.ASSOCIATE_WITH_THREAD, associatewiththread.toString());
    attrList.put(ResourceConstants.MATCH_CONNECTIONS, matchconnections.toString());
    attrList.put(ResourceConstants.MAX_CONNECTION_USAGE_COUNT, maxconnectionusagecount);
    attrList.put(ResourceConstants.CONNECTOR_CONNECTION_POOL_NAME, poolname);
    attrList.put(ResourceConstants.CONN_TRANSACTION_SUPPORT, transactionsupport);
    attrList.put(ResourceConstants.PING, ping.toString());
    attrList.put(ResourceConstants.POOLING, pooling.toString());
    ResourceStatus rs;
    try {
        ConnectorConnectionPoolManager connPoolMgr = connectorConnectionPoolManagerProvider.get();
        rs = connPoolMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        Logger.getLogger(CreateConnectorConnectionPool.class.getName()).log(Level.SEVERE, "Unable to create connector connection pool " + poolname, e);
        String def = "Connector connection pool: {0} could not be created, reason: {1}";
        report.setMessage(localStrings.getLocalString("create.connector.connection.pool.fail", def, poolname) + " " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    if (rs.getStatus() == ResourceStatus.FAILURE) {
        ec = ActionReport.ExitCode.FAILURE;
        if (rs.getMessage() != null) {
            report.setMessage(rs.getMessage());
        } else {
            report.setMessage(localStrings.getLocalString("create.connector.connection.pool.fail", "Connector connection pool {0} creation failed.", poolname));
        }
        if (rs.getException() != null)
            report.setFailureCause(rs.getException());
    } else {
        // TODO only for DAS ?
        if ("true".equalsIgnoreCase(ping.toString())) {
            ActionReport subReport = report.addSubActionsReport();
            ParameterMap parameters = new ParameterMap();
            parameters.set("pool_name", poolname);
            commandRunner.getCommandInvocation("ping-connection-pool", subReport, context.getSubject()).parameters(parameters).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                subReport.setMessage(localStrings.getLocalString("ping.create.connector.connection.pool.fail", "\nAttempting to ping during Connector Connection " + "Pool Creation : {0} - Failed.", poolname));
                subReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            } else {
                subReport.setMessage(localStrings.getLocalString("ping.create.connector.connection.pool.success", "\nAttempting to ping during Connector Connection " + "Pool Creation : {0} - Succeeded.", poolname));
            }
        }
    }
    if (rs.getMessage() != null) {
        report.setMessage(rs.getMessage());
    }
    report.setActionExitCode(ec);
}
Also used : HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Aggregations

ActionReport (org.glassfish.api.ActionReport)508 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)86 Properties (java.util.Properties)83 Config (com.sun.enterprise.config.serverbeans.Config)73 PropertyVetoException (java.beans.PropertyVetoException)72 ParameterMap (org.glassfish.api.admin.ParameterMap)66 Logger (java.util.logging.Logger)56 IOException (java.io.IOException)47 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)43 File (java.io.File)41 CommandTarget (org.glassfish.config.support.CommandTarget)30 Target (org.glassfish.internal.api.Target)30 Map (java.util.Map)27 Server (com.sun.enterprise.config.serverbeans.Server)25 List (java.util.List)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 CommandRunner (org.glassfish.api.admin.CommandRunner)23 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)23 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)19