Search in sources :

Example 1 with DefaultResourceProxy

use of org.glassfish.api.naming.DefaultResourceProxy in project Payara by payara.

the class ListJMSResources 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();
    ArrayList<Map<String, String>> list = new ArrayList<>();
    Properties extraProperties = new Properties();
    Collection adminObjectResourceList = domain.getResources().getResources(AdminObjectResource.class);
    Collection connectorResourcesList = domain.getResources().getResources(ConnectorResource.class);
    Object[] connectorResources = connectorResourcesList.toArray();
    Object[] adminObjectResources = adminObjectResourceList.toArray();
    if (resourceType == null) {
        try {
            // list all JMS resources
            for (Object r : adminObjectResources) {
                AdminObjectResource adminObject = (AdminObjectResource) r;
                if (JMSRA.equals(adminObject.getResAdapter())) {
                    Map<String, String> m = new HashMap<>();
                    m.put("name", adminObject.getJndiName());
                    list.add(m);
                }
            }
            for (Object c : connectorResources) {
                ConnectorResource cr = (ConnectorResource) c;
                ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
                if (cp != null && JMSRA.equals(cp.getResourceAdapterName())) {
                    Map<String, String> m = new HashMap<>();
                    m.put("name", cr.getJndiName());
                    list.add(m);
                }
            }
        } catch (Exception e) {
            report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources") + " " + e.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
    } else {
        switch(resourceType) {
            case TOPIC_CF:
            case QUEUE_CF:
            case UNIFIED_CF:
                for (Object c : connectorResources) {
                    ConnectorResource cr = (ConnectorResource) c;
                    ConnectorConnectionPool cp = (ConnectorConnectionPool) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorConnectionPool.class, cr.getPoolName());
                    if (cp != null && resourceType.equals(cp.getConnectionDefinitionName()) && JMSRA.equals(cp.getResourceAdapterName())) {
                        Map<String, String> m = new HashMap<>();
                        m.put("name", cr.getJndiName());
                        list.add(m);
                    }
                }
                break;
            case TOPIC:
            case QUEUE:
                for (Object r : adminObjectResources) {
                    AdminObjectResource res = (AdminObjectResource) r;
                    if (resourceType.equals(res.getResType()) && JMSRA.equals(res.getResAdapter())) {
                        Map<String, String> m = new HashMap<>();
                        m.put("name", res.getJndiName());
                        list.add(m);
                    }
                }
                break;
        }
    }
    if (!list.isEmpty()) {
        List<Map<String, String>> resourceList = CommandTarget.DOMAIN.isValid(habitat, target) ? list : filterListForTarget(list);
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (Map<String, String> m : resourceList) {
            String jndiName = m.get("name");
            final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
            part.setMessage(jndiName);
            String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
            if (logicalName != null) {
                m.put("logical-jndi-name", logicalName);
            }
        }
        extraProperties.put("jmsResources", resourceList);
    }
    report.setExtraProperties(extraProperties);
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) DefaultResourceProxy(org.glassfish.api.naming.DefaultResourceProxy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) Collection(java.util.Collection) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) HashMap(java.util.HashMap) Map(java.util.Map) ConnectorResource(org.glassfish.connectors.config.ConnectorResource)

Example 2 with DefaultResourceProxy

use of org.glassfish.api.naming.DefaultResourceProxy 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 3 with DefaultResourceProxy

use of org.glassfish.api.naming.DefaultResourceProxy 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 4 with DefaultResourceProxy

use of org.glassfish.api.naming.DefaultResourceProxy in project Payara by payara.

the class ListManagedExecutorServices 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<ManagedExecutorService> managedExecutorServices = domain.getResources().getResources(ManagedExecutorService.class);
        List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (ManagedExecutorService managedExecutorService : managedExecutorServices) {
            String jndiName = managedExecutorService.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("managedExecutorServices", resourcesList);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.managed.executor.service.failed", "List managed executor services 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) ManagedExecutorService(org.glassfish.concurrent.config.ManagedExecutorService) DefaultManagedExecutorService(org.glassfish.concurrent.runtime.deployer.DefaultManagedExecutorService)

Example 5 with DefaultResourceProxy

use of org.glassfish.api.naming.DefaultResourceProxy in project Payara by payara.

the class ListManagedScheduledExecutorServices 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<ManagedScheduledExecutorService> managedScheduledExecutorServices = domain.getResources().getResources(ManagedScheduledExecutorService.class);
        List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
        List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
        for (ManagedScheduledExecutorService managedScheduledExecutorService : managedScheduledExecutorServices) {
            String jndiName = managedScheduledExecutorService.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("managedScheduledExecutorServices", resourcesList);
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.managed.scheduled.executor.service.failed", "List managed scheduled executor services 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) ManagedScheduledExecutorService(org.glassfish.concurrent.config.ManagedScheduledExecutorService) DefaultManagedScheduledExecutorService(org.glassfish.concurrent.runtime.deployer.DefaultManagedScheduledExecutorService)

Aggregations

ActionReport (org.glassfish.api.ActionReport)6 DefaultResourceProxy (org.glassfish.api.naming.DefaultResourceProxy)6 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ContextService (org.glassfish.concurrent.config.ContextService)1 ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)1 ManagedScheduledExecutorService (org.glassfish.concurrent.config.ManagedScheduledExecutorService)1 ManagedThreadFactory (org.glassfish.concurrent.config.ManagedThreadFactory)1 DefaultContextService (org.glassfish.concurrent.runtime.deployer.DefaultContextService)1 DefaultManagedExecutorService (org.glassfish.concurrent.runtime.deployer.DefaultManagedExecutorService)1 DefaultManagedScheduledExecutorService (org.glassfish.concurrent.runtime.deployer.DefaultManagedScheduledExecutorService)1 DefaultManagedThreadFactory (org.glassfish.concurrent.runtime.deployer.DefaultManagedThreadFactory)1 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)1 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)1 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)1 JdbcResource (org.glassfish.jdbc.config.JdbcResource)1