Search in sources :

Example 96 with Server

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

the class RemoveInstanceFromDeploymentGroupCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    DeploymentGroup deploymentGroup = domain.getDeploymentGroupNamed(deploymentGroupName);
    if (deploymentGroup == null) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage("Deployment Group " + deploymentGroupName + " does not exist");
        return;
    }
    List<String> instances = Arrays.asList(instanceName.split(","));
    for (String instance : instances) {
        Server server = domain.getServerNamed(instance);
        if (server == null) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage("Instance " + instance + " does not exist");
            return;
        }
        DGServerRef deploymentGroupServerRef = deploymentGroup.getDGServerRefByRef(instance);
        if (deploymentGroupServerRef == null) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage("Deployment Group " + deploymentGroupName + " does not contain server " + instance);
            return;
        }
        // OK set up the reference
        try {
            ConfigSupport.apply((DeploymentGroup dg1) -> {
                dg1.getDGServerRef().remove(deploymentGroupServerRef);
                return null;
            }, deploymentGroup);
        } catch (TransactionFailure e) {
            report.setMessage("Failed to remove instance from the deployment group");
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
        }
        // now run the command to remove application deploymentGroupServerRef to the instance
        for (ApplicationRef applicationRef : deploymentGroup.getApplicationRef()) {
            CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("delete-application-ref", report, context.getSubject());
            ParameterMap parameters = new ParameterMap();
            parameters.add("target", instance);
            parameters.add("name", applicationRef.getRef());
            inv.parameters(parameters).execute();
        }
        // now run the command to remove resource deploymentGroupServerRef to the instance
        for (ResourceRef resourceRef : deploymentGroup.getResourceRef()) {
            CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("delete-resource-ref", report, context.getSubject());
            ParameterMap parameters = new ParameterMap();
            parameters.add("target", instance);
            parameters.add("reference_name", resourceRef.getRef());
            inv.parameters(parameters).execute();
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) DGServerRef(fish.payara.enterprise.config.serverbeans.DGServerRef) ParameterMap(org.glassfish.api.admin.ParameterMap) ResourceRef(com.sun.enterprise.config.serverbeans.ResourceRef) ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) CommandRunner(org.glassfish.api.admin.CommandRunner) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 97 with Server

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

the class ApplicationConfigListener method transactionCommited.

public void transactionCommited(final List<PropertyChangeEvent> changes) {
    boolean isUpdatingAttribute = true;
    for (PropertyChangeEvent event : changes) {
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        if (event.getSource() instanceof Applications) {
            if (event.getPropertyName().equals(ServerTags.APPLICATION)) {
                if (oldValue == null || newValue == null) {
                    // we are adding/removing application element here
                    // and updating existing attribute
                    isUpdatingAttribute = false;
                    break;
                }
            }
        } else if (event.getSource() instanceof Server || event.getSource() instanceof Cluster) {
            if (event.getPropertyName().equals(ServerTags.APPLICATION_REF)) {
                if (oldValue == null || newValue == null) {
                    // we are adding/removing application-ref element here
                    // and updating existing attribute
                    isUpdatingAttribute = false;
                    break;
                }
            }
        }
    }
    if (!isUpdatingAttribute) {
        // skip the config listener
        return;
    }
    for (PropertyChangeEvent event : changes) {
        if (event.getSource() instanceof Application || event.getSource() instanceof ApplicationRef || event.getSource() instanceof Property) {
            Object oldValue = event.getOldValue();
            Object newValue = event.getNewValue();
            String propertyName = null;
            if (oldValue != null && newValue != null && oldValue instanceof String && newValue instanceof String && !((String) oldValue).equals((String) newValue)) {
                // if it's an attribute change of the application
                // element or application-ref element
                Object parent = event.getSource();
                String appName = null;
                if (parent instanceof Application) {
                    appName = ((Application) parent).getName();
                    propertyName = event.getPropertyName();
                } else if (parent instanceof ApplicationRef) {
                    appName = ((ApplicationRef) parent).getRef();
                    propertyName = event.getPropertyName();
                } else if (parent instanceof Property) {
                    appName = ((Property) parent).getParent(Application.class).getName();
                    propertyName = ((Property) parent).getName();
                }
                // anything
                if (applications.getApplication(appName) == null) {
                    return;
                }
                if (ServerTags.ENABLED.equals(propertyName)) {
                    // enable or disable application accordingly
                    handleAppEnableChange(event.getSource(), appName, Boolean.valueOf((String) newValue));
                } else if (ServerTags.CONTEXT_ROOT.equals(propertyName) || ServerTags.VIRTUAL_SERVERS.equals(propertyName) || ServerTags.AVAILABILITY_ENABLED.equals(propertyName) || ServerTags.CDI_DEV_MODE_ENABLED_PROP.equals(propertyName)) {
                    // for other changes, reload the application
                    handleOtherAppConfigChanges(event.getSource(), appName);
                }
            }
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) Applications(com.sun.enterprise.config.serverbeans.Applications) Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) Application(com.sun.enterprise.config.serverbeans.Application) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) Property(org.jvnet.hk2.config.types.Property)

Example 98 with Server

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

the class AbstractListCommandProxy method execute.

@Override
public final void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    ActionReport subReport = null;
    if (!preInvoke(context, actionReport)) {
        commandsExitCode = ActionReport.ExitCode.FAILURE;
        return;
    }
    if (targetUtil.isCluster(target)) {
        for (Server serverInst : targetUtil.getInstances(target)) {
            try {
                subReport = executeInternalCommand(context, serverInst.getName());
                break;
            } catch (Throwable ex) {
                logger.log(Level.INFO, "Got exception: " + ex.toString());
            }
        }
    } else if (target.equals("server")) {
        subReport = executeInternalCommand(context, target);
    } else {
        subReport = executeInternalCommand(context, target);
    }
    if (subReport != null) {
        if (subReport.getExtraProperties() != null && subReport.getExtraProperties().size() > 0)
            postInvoke(context, subReport);
        else {
            if (subReport.getSubActionsReport() != null && subReport.getSubActionsReport().size() > 0 && subReport.getSubActionsReport().get(0).getExtraProperties() != null) {
                postInvoke(context, subReport.getSubActionsReport().get(0));
            } else {
                actionReport.setMessage(subReport.getMessage());
                commandsExitCode = subReport.getActionExitCode();
            }
        }
    }
    actionReport.setActionExitCode(commandsExitCode);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 99 with Server

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

the class RegistrationSupport method processResourceRef.

/**
 *        Examine the MBean to see if it is a ResourceRef that should be manifested under this server,
 *        and if so, register a JSR 77 MBean for it.
 */
public ObjectName processResourceRef(final ResourceRef ref) {
    if (ref == null) {
        throw new IllegalArgumentException("resource-ref is null");
    }
    if (!mServer.getName().equals(ref.getParent(Server.class).getName())) {
        cdebug("ResourceRef is not a child of server " + getObjectName(mServer));
        return null;
    }
    // find the referenced resource
    Resource res = null;
    List<Resource> resources = getDomain().getResources().getResources();
    for (Resource resource : resources) {
        String name = null;
        if (resource instanceof BindableResource) {
            name = ((BindableResource) resource).getJndiName();
        }
        if (resource instanceof Named) {
            name = ((Named) resource).getName();
        }
        if (resource instanceof ResourcePool) {
            name = ((ResourcePool) resource).getName();
        }
        if (name != null && name.equals(ref.getRef()))
            res = resource;
    }
    if (res == null) {
        throw new IllegalArgumentException("ResourceRef refers to non-existent resource: " + ref);
    }
    final String configType = Util.getTypeProp(getObjectName(res));
    final Class<J2EEManagedObjectImplBase> implClass = CONFIG_RESOURCE_TYPES.get(configType);
    if (implClass == null) {
        mLogger.fine("Unrecognized resource type for JSR 77 purposes: " + getObjectName(res));
        return null;
    }
    final Class<J2EEManagedObject> intf = (Class) ClassUtil.getFieldValue(implClass, "INTF");
    ObjectName mbean77 = null;
    try {
        final MetadataImpl meta = new MetadataImpl();
        meta.setCorrespondingRef(getObjectName(ref));
        meta.setCorrespondingConfig(getObjectName(res));
        mbean77 = registerJ2EEChild(mJ2EEServer.objectName(), meta, intf, implClass, Util.getNameProp(getObjectName(res)));
        synchronized (mConfigRefTo77) {
            mConfigRefTo77.put(getObjectName(ref), mbean77);
        }
    } catch (final Exception e) {
        mLogger.log(Level.INFO, AMXEELoggerInfo.cantRegisterMbean, new Object[] { getObjectName(ref), e });
    }
    // cdebug( "Registered " + child + " for  config resource " + amx.objectName() );
    return mbean77;
}
Also used : Named(org.glassfish.api.admin.config.Named) Server(com.sun.enterprise.config.serverbeans.Server) Resource(com.sun.enterprise.config.serverbeans.Resource) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource) ResourcePool(com.sun.enterprise.config.serverbeans.ResourcePool) BindableResource(com.sun.enterprise.config.serverbeans.BindableResource)

Example 100 with Server

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

the class DatabaseEJBTimerService method memberRemoved.

@Override
public void memberRemoved(MemberEvent event) {
    // work out whether we should be attempting to migrate timers
    String server = event.getServer();
    String group = event.getServerGroup();
    String thisServer = serverEnv.getInstanceName();
    // check whether the server is any of the same clusters or deployment groups
    // as the disappeared server and if so migrate timers
    boolean migrate = false;
    Cluster forServer = domain.getClusterForInstance(server);
    if (forServer != null) {
        for (Server instance : forServer.getInstances()) {
            if (instance.getName().equals(thisServer)) {
                // if I am in the same cluster
                migrate = true;
                break;
            }
        }
    }
    if (!migrate) {
        for (DeploymentGroup deploymentGroup : domain.getDeploymentGroupsForInstance(server)) {
            for (Server instance : deploymentGroup.getInstances()) {
                if (instance.getName().equals(thisServer)) {
                    // if I am in the same cluster
                    migrate = true;
                    break;
                }
            }
        }
    }
    if (migrate) {
        migrateTimers(event.getServer());
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) PayaraCluster(fish.payara.nucleus.cluster.PayaraCluster) Cluster(com.sun.enterprise.config.serverbeans.Cluster) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Aggregations

Server (com.sun.enterprise.config.serverbeans.Server)101 ActionReport (org.glassfish.api.ActionReport)32 Cluster (com.sun.enterprise.config.serverbeans.Cluster)25 Domain (com.sun.enterprise.config.serverbeans.Domain)15 Node (com.sun.enterprise.config.serverbeans.Node)15 Config (com.sun.enterprise.config.serverbeans.Config)14 Properties (java.util.Properties)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 PropertyVetoException (java.beans.PropertyVetoException)11 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)9 ParameterMap (org.glassfish.api.admin.ParameterMap)9 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)8 File (java.io.File)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)8 Logger (java.util.logging.Logger)7 Map (java.util.Map)6 ServerContext (org.glassfish.internal.api.ServerContext)6