Package com.webobjects.monitor._private

Examples of com.webobjects.monitor._private.MHost


    protected void prepareInstances(NSArray<String> appNamesAndNumbers) {
        if (appNamesAndNumbers == null)
            throw new DirectActionException("at least one instance name needs to be specified for type ins", 406);
        for (Enumeration enumeration = appNamesAndNumbers.objectEnumerator(); enumeration.hasMoreElements();) {
            String s = (String) enumeration.nextElement();
            MInstance minstance = siteConfig().instanceWithName(s);
            if (minstance != null)
                instances.addObject(minstance);
            else
                throw new DirectActionException("Unknown instance " + s, 404);
        }
View Full Code Here


        }
        return false;
    }

    public String pathDiff() {
        MInstance myInstance = myInstance();
        MApplication myApplication = myInstance.application();
        MHost myHost = myInstance.host();
        String appPath = null;

        if (myHost.osType().equals("UNIX")) {
            appPath = myApplication.unixPath();
        } else if (myHost.osType().equals("WINDOWS")) {
            appPath = myApplication.winPath();
        } else if (myHost.osType().equals("MACOSX")) {
            appPath = myApplication.macPath();
        }

        if (!safeEquals(myInstance.path(), appPath)) {
            return _diffString;
        }
        return _emptyString;
    }
View Full Code Here

        }
        return _emptyString;
    }

    public String minDiff() {
        MInstance myInstance = myInstance();
        MApplication myApplication = myInstance.application();
        if (!safeEquals(myInstance.minimumActiveSessionsCount(), myApplication.minimumActiveSessionsCount())) {
            return _diffString;
        }
        return _emptyString;
    }
View Full Code Here

        }
        return _emptyString;
    }

    public String cachingDiff() {
        MInstance myInstance = myInstance();
        MApplication myApplication = myInstance.application();
        if (!safeEquals(myInstance.cachingEnabled(), myApplication.cachingEnabled())) {
            return _diffString;
        }
        return _emptyString;
    }
View Full Code Here

        }
        return _emptyString;
    }

    public String outputDiff() {
        MInstance myInstance = myInstance();
        MApplication myApplication = myInstance.application();
        MHost myHost = myInstance.host();
        String appOutputPath = null;

        if (myHost.osType().equals("UNIX")) {
            appOutputPath = myInstance.generateOutputPath(myApplication.unixOutputPath());
        } else if (myHost.osType().equals("WINDOWS")) {
            appOutputPath = myInstance.generateOutputPath(myApplication.winOutputPath());
        } else if (myHost.osType().equals("MACOSX")) {
            appOutputPath = myInstance.generateOutputPath(myApplication.macOutputPath());
        }

        if (!safeEquals(myInstance.outputPath(), appOutputPath)) {
            return _diffString;
        }
        return _emptyString;
    }
View Full Code Here

        }
        return _emptyString;
    }

    public String browserDiff() {
        MInstance myInstance = myInstance();
        MApplication myApplication = myInstance.application();
        if (!safeEquals(myInstance.autoOpenInBrowser(), myApplication.autoOpenInBrowser())) {
            return _diffString;
        }
        return _emptyString;
    }
View Full Code Here

        }
        return _emptyString;
    }

    public String debugDiff() {
        MInstance myInstance = myInstance();
        MApplication myApplication = myInstance.application();
        if (!safeEquals(myInstance.debuggingEnabled(), myApplication.debuggingEnabled())) {
            return _diffString;
        }
        return _emptyString;
    }
View Full Code Here

        }
        return _emptyString;
    }

    public String lifebeatDiff() {
        MInstance myInstance = myInstance();
        MApplication myApplication = myInstance.application();
        if (!safeEquals(myInstance.lifebeatInterval(), myApplication.lifebeatInterval())) {
            return _diffString;
        }
        return _emptyString;
    }
View Full Code Here

        }
        return _emptyString;
    }

    public String argsDiff() {
        MInstance myInstance = myInstance();
        MApplication myApplication = myInstance.application();
        if (!safeEquals(myInstance.additionalArgs(), myApplication.additionalArgs())) {
            return _diffString;
        }
        return _emptyString;
    }
View Full Code Here

                            // update-remove - for each instance listed - instanceWithHostnameAndPort + removeInstance_W
                            for (Enumeration e = instanceArray.objectEnumerator(); e.hasMoreElements(); ) {
                                NSDictionary anInst = (NSDictionary) e.nextElement();
                                String hostName = (String) anInst.valueForKey("hostName");
                                Integer port = (Integer) anInst.valueForKey("port");
                                MInstance anMInstance = aConfig.instanceWithHostnameAndPort(hostName, port);
                                if (anMInstance == null) {
                                    element = new NSDictionary(new Object[]{Boolean.FALSE, _hostName + ": Instance " +hostName+"-"+port+ " not found; REMOVE failed"}, errorKeys);
                                    instanceArrayResponse.addObject(element);
                                } else {
                                    aConfig.removeInstance_W(anMInstance);
                                    instanceArrayResponse.addObject(successElement);
                                }
                            }
                            removeResponse.takeValueForKey(instanceArrayResponse, "instanceArray");
                        }
                        updateWotaskdResponse.takeValueForKey(removeResponse, "remove");
                    }

                    if (addDict != null) {
                        NSMutableDictionary addResponse = new NSMutableDictionary(1);

                        NSArray hostArray = (NSArray) addDict.valueForKey("hostArray");
                        NSArray applicationArray = (NSArray) addDict.valueForKey("applicationArray");
                        NSArray instanceArray = (NSArray) addDict.valueForKey("instanceArray");

                        if (hostArray != null) {
                            NSMutableArray hostArrayResponse = new NSMutableArray(hostArray.count());

                            // update-add - for each host listed - addHost_W
                            for (Enumeration e = hostArray.objectEnumerator(); e.hasMoreElements(); ) {
                                NSDictionary aHost = (NSDictionary) e.nextElement();
                                aConfig.addHost_W(new MHost(aHost, aConfig));
                                hostArrayResponse.addObject(successElement);
                            }
                            addResponse.takeValueForKey(hostArrayResponse, "hostArray");
                        }
                        if (applicationArray != null) {
                            NSMutableArray applicationArrayResponse = new NSMutableArray(applicationArray.count());

                            // update-add - for each application listed - addApplication_W
                            for (Enumeration e = applicationArray.objectEnumerator(); e.hasMoreElements(); ) {
                                NSDictionary anApp = (NSDictionary) e.nextElement();
                                aConfig.addApplication_W(new MApplication(anApp, aConfig));
                                applicationArrayResponse.addObject(successElement);
                            }
                            addResponse.takeValueForKey(applicationArrayResponse, "applicationArray");
                        }
                        if (instanceArray != null) {
                            NSMutableArray instanceArrayResponse = new NSMutableArray(instanceArray.count());

                            //  update-add - for each instance listed - addInstance_W
                            for (Enumeration e = instanceArray.objectEnumerator(); e.hasMoreElements(); ) {
                                NSDictionary anInst = (NSDictionary) e.nextElement();
                                aConfig.addInstance_W(new MInstance(anInst, aConfig));
                                instanceArrayResponse.addObject(successElement);
                            }
                            addResponse.takeValueForKey(instanceArrayResponse, "instanceArray");
                        }
                        updateWotaskdResponse.takeValueForKey(addResponse, "add");
                    }

                    if (configureDict != null) {
                        NSMutableDictionary configureResponse = new NSMutableDictionary(2);

                        NSDictionary siteDict = (NSDictionary) configureDict.valueForKey("site");
                        NSArray hostArray = (NSArray) configureDict.valueForKey("hostArray");
                        NSArray applicationArray = (NSArray) configureDict.valueForKey("applicationArray");
                        NSArray instanceArray = (NSArray) configureDict.valueForKey("instanceArray");

                        if (siteDict != null) {
                            // update-configure - siteConfig.updateValues
                            aConfig.updateValues(siteDict);
                            configureResponse.takeValueForKey(successElement, "site");
                        }
                        if (hostArray != null) {
                            NSMutableArray hostArrayResponse = new NSMutableArray(hostArray.count());

                            // update-configure - for each host listed - hostWithName + updateValues
                            for (Enumeration e = hostArray.objectEnumerator(); e.hasMoreElements(); ) {
                                NSDictionary aHost = (NSDictionary) e.nextElement();
                                String name = (String) aHost.valueForKey("name");
                                MHost anMHost = aConfig.hostWithName(name);
                                if (anMHost == null) {
                                    element = new NSDictionary(new Object[]{Boolean.FALSE, _hostName + ": Host " +name+ " not found; UPDATE failed"}, errorKeys);
                                    hostArrayResponse.addObject(element);
                                } else {
                                    anMHost.updateValues(aHost);
                                    hostArrayResponse.addObject(successElement);
                                }
                            }
                            configureResponse.takeValueForKey(hostArrayResponse, "hostArray");
                        }
                        if (applicationArray != null) {
                            NSMutableArray applicationArrayResponse = new NSMutableArray(applicationArray.count());

                            // update-configure - for each application listed - applicationWithName + updateValues
                            for (Enumeration e = applicationArray.objectEnumerator(); e.hasMoreElements(); ) {
                                NSDictionary anApp = (NSDictionary) e.nextElement();
                                String name = (String) anApp.valueForKey("name");
                                MApplication anMApplication = aConfig.applicationWithName(name);
                                // if I can't find the application, I might be updating the name - in that case, look under the oldname.
                                if (anMApplication == null) {
                                    name = (String) anApp.valueForKey("oldname");
                                    anMApplication = aConfig.applicationWithName(name);
                                }

                                if (anMApplication == null) {
                                    element = new NSDictionary(new Object[]{Boolean.FALSE, _hostName + ": Application " +name+ " not found; UPDATE failed"}, errorKeys);
                                    applicationArrayResponse.addObject(element);
                                } else {
                                    anMApplication.updateValues(anApp);
                                    applicationArrayResponse.addObject(successElement);
                                }
                            }
                            configureResponse.takeValueForKey(applicationArrayResponse, "applicationArray");
                        }
                        if (instanceArray != null) {
                            NSMutableArray instanceArrayResponse = new NSMutableArray(instanceArray.count());

                            // update-configure - for each instance listed - instanceWithHostnameAndPort + updateValues
                            for (Enumeration e = instanceArray.objectEnumerator(); e.hasMoreElements(); ) {
                                NSDictionary anInst = (NSDictionary) e.nextElement();
                                String hostName = (String) anInst.valueForKey("hostName");
                                Integer port = (Integer) anInst.valueForKey("port");
                                MInstance anMInstance = aConfig.instanceWithHostnameAndPort(hostName, port);
                                // if I can't find the instance, I might be updating the port - in that case, look under the oldport number.
                                if (anMInstance == null) {
                                    port = (Integer) anInst.valueForKey("oldport");
                                    anMInstance = aConfig.instanceWithHostnameAndPort(hostName, port);
                                }
                                if (anMInstance == null) {
                                    element = new NSDictionary(new Object[]{Boolean.FALSE, _hostName + ": Instance " +hostName+"-"+port+ " not found; UPDATE failed"}, errorKeys);
                                    instanceArrayResponse.addObject(element);
                                } else {
                                    anMInstance.updateValues(anInst);
                                    instanceArrayResponse.addObject(successElement);
                                }
                            }
                            configureResponse.takeValueForKey(instanceArrayResponse, "instanceArray");
                        }
                        updateWotaskdResponse.takeValueForKey(configureResponse, "configure");
                    }
                }
                monitorResponse.takeValueForKey(updateWotaskdResponse, "updateWotaskdResponse");
            } finally {
                theApplication._lock.endWriting();
            }
        }


        // Checking for Commands
        if (commandWotaskdArray != null) {
            int instArrayCount = commandWotaskdArray.count();
            NSMutableArray commandWotaskdResponse = new NSMutableArray(instArrayCount);

            if (instArrayCount < 2) {
                commandWotaskdResponse.addObject(_argumentNumberCommandError);
            } else {
                String command = (String) commandWotaskdArray.objectAtIndex(0);

                if ( (command.equals("START")) || (command.equals("CLEAR")) ||
                     (command.equals("STOP"))  || (command.equals("REFUSE")) ||
                     (command.equals("ACCEPT"))|| (command.equals("QUIT")) ) {
                    commandWotaskdResponse.addObject(successElement);
                } else {
                    element = new NSDictionary(new Object[]{Boolean.FALSE, _hostName + " - INTERNAL ERROR: Invalid Command " + command}, errorKeys);
                    commandWotaskdResponse.addObject(element);
                }

                // Go through each instance and do whatever it is that we do
                for (int i=1; i<instArrayCount; i++) {
                    NSDictionary instDict = (NSDictionary) commandWotaskdArray.objectAtIndex(i);
                    String hostName = (String) instDict.valueForKey("hostName");
                    Integer port = (Integer) instDict.valueForKey("port");
                    theApplication._lock.startReading();
                    try {
                        MInstance anInstance = aConfig.instanceWithHostnameAndPort(hostName, port);
                        if (anInstance != null) {
                            if (anInstance.isLocal_W()) {
                                if (command.equals("START")) {
                                    String errorMsg = theApplication.localMonitor().startInstance(anInstance);
                                    if (errorMsg != null) {
                                        element = new NSDictionary(new Object[]{Boolean.FALSE, errorMsg}, errorKeys);
                                        commandWotaskdResponse.addObject(element);
                                    }
                                } else if (command.equals("CLEAR")) {
                                    anInstance.removeAllDeaths();
                                    commandWotaskdResponse.addObject(successElement);
                                } else {
                                    try {
                                        if (command.equals("STOP")) {
                                          //we need to expect a response here
                                            if (theApplication.localMonitor().terminateInstance(anInstance) == null)
                                              throw new MonitorException("No response to STOP " + anInstance.displayName());
                                        } else if (command.equals("REFUSE")) {
                                          //we need to expect a response here
                                            if (theApplication.localMonitor().stopInstance(anInstance) == null)
                                              throw new MonitorException("No response to REFUSE " + anInstance.displayName());
                                        } else if (command.equals("ACCEPT")) {
                                            if (theApplication.localMonitor().setAcceptInstance(anInstance) == null)
                                              throw new MonitorException("No response to ACCEPT " + anInstance.displayName());
                                            //we got a response, cancel any force quit task
                                            anInstance.cancelForceQuitTask();
                                        } else if (command.equals("QUIT")) {
                                            anInstance.setShouldDie(true);
                                        }
                                        commandWotaskdResponse.addObject(successElement);
                                    } catch (MonitorException me) {
                                        element = new NSDictionary(new Object[]{Boolean.FALSE, me.getMessage()}, errorKeys);
                                        commandWotaskdResponse.addObject(element);
                                    }
                                }
                            } else {
                                //element = new NSDictionary(new Object[]{Boolean.FALSE, anInstance.displayName() + " does not exist on " + _hostName + "; " + command + " failed"}, errorKeys);
                                //commandWotaskdResponse.addObject(element);
                                commandWotaskdResponse.addObject(successElement);
                            }
                        } else {
                            element = new NSDictionary(new Object[]{Boolean.FALSE, _hostName + ": No instance found for Host " + hostName + " and Port: " + port + "; " + command + " failed"}, errorKeys);
                            commandWotaskdResponse.addObject(element);
                        }
                    } finally {
                        theApplication._lock.endReading();
                    }
                }
            }
            monitorResponse.takeValueForKey(commandWotaskdResponse, "commandWotaskdResponse");
        }

       
        // Checking for a Query
        if (queryWotaskdString != null) {
            NSMutableDictionary queryWotaskdResponse = new NSMutableDictionary(1);

            if (queryWotaskdString.equals("SITE")) {
                theApplication._lock.startReading();
                try {
                    queryWotaskdResponse.takeValueForKey(aConfig.dictionaryForArchive(), "SiteConfig");
                } finally {
                    theApplication._lock.endReading();
                }
            } else if (queryWotaskdString.equals("HOST")) {
                // query - host.runningInstancesCount_W
                if (hostResponse == null) {
                    Integer runningInstances = Integer.valueOf(0);
                    String processorType = System.getProperties().getProperty("os.arch");
                    String operatingSystem = System.getProperties().getProperty("os.name") + " " + System.getProperties().getProperty("os.version");

                    hostResponse = new NSMutableDictionary(new Object[]{runningInstances, processorType, operatingSystem}, hostQueryKeys);
                }
                theApplication._lock.startReading();
                try {
                    if (aConfig.localHost() != null) {
                        hostResponse.takeValueForKey(aConfig.localHost().runningInstancesCount_W(), "runningInstances");
                    } else {
                        hostResponse.takeValueForKey(_NSUtilities.IntegerForInt(0), "runningInstances");
                    }
                } finally {
                    theApplication._lock.endReading();
                }
                queryWotaskdResponse.takeValueForKey(hostResponse, "hostResponse");
            } else if (queryWotaskdString.equals("APPLICATION")) {
                NSMutableArray applicationResponse = null;
                theApplication._lock.startReading();
                try {
                    NSArray appArray = aConfig.applicationArray();
                    int appArrayCount = appArray.count();
                    MApplication anApp;
                    String name;
                    Integer runningInstances;
                    NSDictionary elementApp;

                    applicationResponse = new NSMutableArray(appArrayCount);

                    // query - for each application - runningInstancesCount_W();
                    for (int i=0; i<appArrayCount; i++) {
                        anApp = (MApplication) appArray.objectAtIndex(i);
                        name = anApp.name();
                        runningInstances = anApp.runningInstancesCount_W();
                        elementApp = new NSDictionary(new Object[]{name, runningInstances}, appQueryKeys);
                        applicationResponse.addObject(elementApp);
                    }
                } finally {
                    theApplication._lock.endReading();
                }

                queryWotaskdResponse.takeValueForKey(applicationResponse, "applicationResponse");
            } else if (queryWotaskdString.equals("INSTANCE")) {
                NSMutableArray instanceResponse = null;
                theApplication._lock.startReading();
                try {
                    NSArray instanceArray = (aConfig.localHost() != null) ? aConfig.localHost().instanceArray() : NSArray.EmptyArray;
                    int instanceArrayCount = instanceArray.count();

                    MInstance anInstance;
                    String applicationName;
                    Integer id;
                    String host;
                    Integer port;
                    String runningState;
                    Boolean refusingNewSessions;
                    NSDictionary statistics;
                    NSArray deaths;
                    String nextShutdown;
                    NSDictionary elementInst;

                    instanceResponse = new NSMutableArray(instanceArrayCount);

                    NSMutableArray runningInstanceArray = new NSMutableArray();
                    for (Enumeration e = instanceArray.objectEnumerator(); e.hasMoreElements(); ) {
                        MInstance anInst = (MInstance) e.nextElement();
                        if (anInst.isRunning_W()) {
                            runningInstanceArray.addObject(anInst);
                        }
                    }
                    getStatisticsForInstanceArray(runningInstanceArray, errorResponse);
View Full Code Here

TOP

Related Classes of com.webobjects.monitor._private.MHost

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.