Search in sources :

Example 11 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class ReferenceConstrainClusterTest method clusterServerRefInvalid.

@Test
public void clusterServerRefInvalid() throws TransactionFailure {
    Cluster cluster = habitat.getService(Cluster.class, "clusterA");
    assertNotNull(cluster);
    ServerRef sref = cluster.getServerRef().get(0);
    ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("ref", "server-nonexist");
    changes.put(serverConfig, configChanges);
    try {
        ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
        cs.apply(changes);
        fail("Can not reach this point");
    } catch (TransactionFailure tf) {
        ConstraintViolationException cv = findConstrViolation(tf);
        assertNotNull(cv);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ConstraintViolationException(javax.validation.ConstraintViolationException) ConfigBean(org.jvnet.hk2.config.ConfigBean) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) HashMap(java.util.HashMap) Map(java.util.Map) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 12 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class ReferenceConstrainClusterTest method clusterServerRefValid.

@Test
public void clusterServerRefValid() throws TransactionFailure {
    Cluster cluster = habitat.getService(Cluster.class, "clusterA");
    assertNotNull(cluster);
    ServerRef sref = cluster.getServerRef().get(0);
    ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("ref", "server");
    changes.put(serverConfig, configChanges);
    try {
        ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
        cs.apply(changes);
    } catch (TransactionFailure tf) {
        fail("Can not reach this point");
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ConfigBean(org.jvnet.hk2.config.ConfigBean) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) HashMap(java.util.HashMap) Map(java.util.Map) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 13 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class UpdateResourceRef method execute.

/**
 * Execution method for updating the configuration of a ResourceRef. Will be
 * replicated if the target is a cluster.
 *
 * @param context context for the command.
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    // Make a list of all ResourceRefs that need to change
    List<ResourceRef> resourceRefsToChange = new ArrayList<>();
    // Add the ResourceRef from a named server if the target is a server
    Server server = domain.getServerNamed(target);
    // if the target is a server
    if (server != null) {
        ResourceRef serverResourceRef = server.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (serverResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(serverResourceRef);
    }
    // Add the ResourceRef from a named config if the target is a config
    Config config = domain.getConfigNamed(target);
    // if the target is a config
    if (config != null) {
        ResourceRef configResourceRef = config.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (configResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(configResourceRef);
    }
    // Add the ResourceRefs from a named cluster if the target is a cluster
    Cluster cluster = domain.getClusterNamed(target);
    // if the target is a cluster
    if (cluster != null) {
        ResourceRef clusterResourceRef = cluster.getResourceRef(name);
        // if the ResourceRef doesn't exist
        if (clusterResourceRef == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(clusterResourceRef);
        for (Server instance : cluster.getInstances()) {
            ResourceRef instanceResourceRef = instance.getResourceRef(name);
            // if the server in the cluster contains the ResourceRef
            if (instanceResourceRef != null) {
                resourceRefsToChange.add(instanceResourceRef);
            }
        }
    }
    // Add the ResourceRefs from a named Deployment Group if the target is a Deployment Group
    DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
    if (dg != null) {
        ResourceRef ref = dg.getResourceRef(name);
        if (ref == null) {
            report.failure(logger, LOCAL_STRINGS.getLocalString("resource.ref.not.exists", "Target {1} does not have a reference to resource {0}.", name, target));
            return;
        }
        resourceRefsToChange.add(ref);
        for (Server instance : dg.getInstances()) {
            ResourceRef instanceResourceRef = instance.getResourceRef(name);
            // if the server in the dg contains the ResourceRef
            if (instanceResourceRef != null) {
                resourceRefsToChange.add(instanceResourceRef);
            }
        }
    }
    // Apply the configuration to the listed ResourceRefs
    try {
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure {
                for (ConfigBeanProxy proxy : params) {
                    if (proxy instanceof ResourceRef) {
                        ResourceRef resourceRefProxy = (ResourceRef) proxy;
                        if (enabled != null) {
                            resourceRefProxy.setEnabled(enabled.toString());
                        }
                    }
                }
                report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return true;
            }
        }, resourceRefsToChange.toArray(new ResourceRef[] {}));
    } catch (TransactionFailure ex) {
        report.failure(logger, ex.getLocalizedMessage());
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) PropertyVetoException(java.beans.PropertyVetoException) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 14 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class CollectLogFiles method getInstanceLogFileDirectory.

/*
       This function is used to get log file details from logging.properties file for given target.
    */
private String getInstanceLogFileDirectory(Server targetServer) throws IOException {
    String logFileDetailsForServer = "";
    String targetConfigName = "";
    Cluster clusterForInstance = targetServer.getCluster();
    if (clusterForInstance != null) {
        targetConfigName = clusterForInstance.getConfigRef();
    } else {
        targetConfigName = targetServer.getConfigRef();
    }
    logFileDetailsForServer = loggingConfig.getLoggingFileDetails(targetConfigName);
    return logFileDetailsForServer;
}
Also used : Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 15 with Cluster

use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.

the class DeleteLogLevel method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    boolean isCluster = false;
    boolean isDas = false;
    boolean isInstance = false;
    StringBuffer successMsg = new StringBuffer();
    boolean isConfig = false;
    boolean success = false;
    String targetConfigName = "";
    Map<String, String> m = new HashMap<String, String>();
    try {
        String[] loggerNames = properties.split("(?<!\\\\):");
        for (final Object key : loggerNames) {
            final String logger_name = (String) key;
            m.put(logger_name + ".level", null);
        }
        Config config = domain.getConfigNamed(target);
        if (config != null) {
            targetConfigName = target;
            isConfig = true;
            Server targetServer = domain.getServerNamed(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
            if (targetServer != null && targetServer.getConfigRef().equals(target)) {
                isDas = true;
            }
            targetServer = null;
        } else {
            Server targetServer = domain.getServerNamed(target);
            if (targetServer != null && targetServer.isDas()) {
                isDas = true;
            } else {
                com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
                if (cluster != null) {
                    isCluster = true;
                    targetConfigName = cluster.getConfigRef();
                } else if (targetServer != null) {
                    isInstance = true;
                    targetConfigName = targetServer.getConfigRef();
                }
            }
            if (isInstance) {
                Cluster clusterForInstance = targetServer.getCluster();
                if (clusterForInstance != null) {
                    targetConfigName = clusterForInstance.getConfigRef();
                }
            }
        }
        if (isCluster || isInstance) {
            loggingConfig.deleteLoggingProperties(m, targetConfigName);
            success = true;
        } else if (isDas) {
            loggingConfig.deleteLoggingProperties(m);
            success = true;
        } else if (isConfig) {
            // This loop is for the config which is not part of any target
            loggingConfig.deleteLoggingProperties(m, targetConfigName);
            success = true;
        } else {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            String msg = localStrings.getLocalString("invalid.target.sys.props", "Invalid target: {0}. Valid default target is a server named ''server'' (default) or cluster name.", target);
            report.setMessage(msg);
            return;
        }
        if (success) {
            successMsg.append(localStrings.getLocalString("delete.log.level.success", "These logging levels are deleted for {0}.", target));
            report.setMessage(successMsg.toString());
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (IOException e) {
        report.setMessage(localStrings.getLocalString("delete.log.level.failed", "Could not delete logger levels for {0}.", target));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) Cluster(com.sun.enterprise.config.serverbeans.Cluster) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Aggregations

Cluster (com.sun.enterprise.config.serverbeans.Cluster)45 Server (com.sun.enterprise.config.serverbeans.Server)26 ActionReport (org.glassfish.api.ActionReport)12 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 Domain (com.sun.enterprise.config.serverbeans.Domain)8 HashMap (java.util.HashMap)8 Config (com.sun.enterprise.config.serverbeans.Config)6 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)5 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)5 PropertyVetoException (java.beans.PropertyVetoException)5 Test (org.junit.Test)5 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)4 Logger (java.util.logging.Logger)4 ConfigBean (org.jvnet.hk2.config.ConfigBean)4 ConfigSupport (org.jvnet.hk2.config.ConfigSupport)4 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)3 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)3