Package org.rhq.enterprise.server.plugin.pc

Examples of org.rhq.enterprise.server.plugin.pc.ControlResults


    @Override
    public ServerPluginControlResults invokeServerPluginControl(PluginKey serverPluginKey, String controlName,
        Configuration params) throws RuntimeException {
        try {
            ControlResults results;
            results = serverPluginManager.invokeServerPluginControl(getSessionSubject(), serverPluginKey, controlName,
                params);

            // ControlDefinition is a server-side only class - we need to convert it to our domain DTO
            ServerPluginControlResults spcr = new ServerPluginControlResults();
            for (Property prop : results.getComplexResults().getProperties()) {
                spcr.getComplexResults().put(prop.deepCopy(true));
            }
            if (!results.isSuccess()) {
                spcr.setError(results.getError());
            }
            return spcr;
        } catch (Throwable t) {
            throw getExceptionToThrowToClient(t);
        }
View Full Code Here


        ServerPluginServiceMBean serverPluginService = LookupUtil.getServerPluginService();
        MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
        if (master != null) {
            AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
            if (pc != null) {
                ControlResults results = pc.invokePluginControl(pluginKey, controlName, params);
                return results;
            } else {
                throw new Exception("There is no known plugin named [" + pluginKey + "]. Cannot invoke [" + controlName
                    + "]");
            }
View Full Code Here

            if (log.isDebugEnabled()) {
                log.debug("Invoked syncServerEndpoint with [name: " + serverName + ", address: " + serverAddr + "]");
            }

            ControlResults results = new ControlResults();

            TopologyManagerLocal cloudMgr = LookupUtil.getTopologyManager();
            Server server = cloudMgr.getServerByName(serverName);

            if (server == null) {
                log.warn("Failed to locate server. No address sync will be performed.");
                results.setError("No update performed. Failed to find server " + server.getName());
                return results;
            }

            if (serverAddr != null) {
                SubjectManagerLocal subjectMgr = LookupUtil.getSubjectManager();

                server.setAddress(serverAddr);
                cloudMgr.updateServer(subjectMgr.getOverlord(), server);
            }

            int updateCount = notifyAgents(server);

            Configuration complexResults = results.getComplexResults();
            complexResults.put(new PropertySimple("results", updateCount + " agents have been updated."));

            if (log.isDebugEnabled()) {
                log.debug("Notified " + updateCount + " agents of the address change.");
            }
View Full Code Here

    }

    @Override
    public ControlResults invoke(String controlOperation, Configuration operationConfig) {

        ControlResults ctrlResult = new ControlResults();

        try {
            if (controlOperation.equals("GET_OAUTH_REQUEST_URL")) {
                // get and store AuthURL in plugin config to be rederend on UI
                ctrlResult.getComplexResults().put(new PropertySimple("authorizationURL", getAuthorizationURL()));
            } else if (controlOperation.equals("GET_ACCESS_TOKEN")) {

                AccessToken accessToken = null;
                String pin = operationConfig.getSimpleValue("pin", null);

                log.debug("using PIN [" + pin + "]");

                if (pin != null && pin.length() > 0) {
                    accessToken = this.twitter.getOAuthAccessToken(requestToken, pin);
                } else {
                    accessToken = this.twitter.getOAuthAccessToken();
                }

                log.debug("ScreenName: " + twitter.getScreenName());
                log.debug("TwitterId: [" + twitter.verifyCredentials().getId() + "]");
                log.debug("token: [" + accessToken.getToken() + "]");
                log.debug("tokenSecret: [" + accessToken.getTokenSecret() + "]");

                // Save the accessToken for future use by this plugin.
                String filePath = storeAccessToken(accessToken);

                ctrlResult.getComplexResults().put(
                    new PropertySimple("accessToken", "token[" + accessToken.getToken() + "] tokenSecret["
                        + accessToken.getTokenSecret() + ""));
                ctrlResult.getComplexResults().put(new PropertySimple("twitterScreenName", twitter.getScreenName()));
                ctrlResult.getComplexResults().put(new PropertySimple("accessTokenFilePath", filePath));
            } else {
                ctrlResult.setError("Invalid Operation! Please Select a valid one.");
            }
        } catch (TwitterException te) {
            log.error("Twitter Error: ", te);
            ctrlResult.setError(te);
        } catch (IOException ioe) {
            log.error("Error storing AccessToken: ", ioe);
            ctrlResult.setError(ioe);
        }

        return ctrlResult;
    }
View Full Code Here

    public void shutdown() {
        log.info("shutdown: " + this);
    }

    public ControlResults invoke(String name, Configuration parameters) {
        ControlResults controlResults = new ControlResults();

        try {
            if (name.equals("getCobblerDistros")) {
                String searchRegex = parameters.getSimpleValue("searchRegex", null);
                Pattern pattern = null;
                if (searchRegex != null) {
                    pattern = Pattern.compile(searchRegex);
                }

                Configuration results = controlResults.getComplexResults();
                PropertyList list = new PropertyList("distros");
                results.put(list);

                Collection<Distro> distros = getAllCobblerDistros().values();
                for (Distro d : distros) {
                    if (pattern == null || pattern.matcher(d.getName()).matches()) {
                        PropertyMap map = new PropertyMap("distro");
                        map.put(new PropertySimple("name", d.getName()));
                        map.put(new PropertySimple("breed", d.getBreed()));
                        map.put(new PropertySimple("osversion", d.getOsVersion()));
                        map.put(new PropertySimple("arch", d.getArch()));
                        map.put(new PropertySimple("initrd", d.getInitrd()));
                        map.put(new PropertySimple("kernel", d.getKernel()));
                        list.add(map);
                    }
                }
            } else if (name.equals("getCobblerProfiles")) {
                String searchRegex = parameters.getSimpleValue("searchRegex", null);
                Pattern pattern = null;
                if (searchRegex != null) {
                    pattern = Pattern.compile(searchRegex);
                }

                Configuration results = controlResults.getComplexResults();
                PropertyList list = new PropertyList("profiles");
                results.put(list);

                List<Profile> profiles = getAllCobblerProfiles();
                for (Profile p : profiles) {
                    if (pattern == null || pattern.matcher(p.getName()).matches()) {
                        PropertyMap map = new PropertyMap("profile");
                        map.put(new PropertySimple("name", p.getName()));
                        map.put(new PropertySimple("distro", p.getDistro()));
                        map.put(new PropertySimple("kickstart", p.getKickstart()));
                        list.add(map);
                    }
                }
            } else if (name.equals("removeCobblerDistros")) {
                String searchRegex = parameters.getSimpleValue("searchRegex", null);
                Pattern pattern = null;
                if (searchRegex != null) {
                    pattern = Pattern.compile(searchRegex);
                }

                if (!this.syncInProgress) {
                    Collection<Distro> distros = getAllCobblerDistros().values();
                    for (Distro d : distros) {
                        if (pattern == null || pattern.matcher(d.getName()).matches()) {
                            if (d.getComment().startsWith(COMMENT_MARKER)) {
                                d.remove();
                            }
                        }
                    }
                } else {
                    controlResults.setError("A synchronize is currently in progress - please wait for it to finish");
                }
            } else {
                controlResults.setError("Unknown operation name: " + name);
            }
        } catch (Exception e) {
            controlResults.setError(e);
        }

        return controlResults;
    }
View Full Code Here

        return info;
    }

    public ControlResults invoke(String name, Configuration parameters) {
        ControlResults controlResults = new ControlResults();
        if (name.equals("testControl")) {
            System.out.println("Invoked 'testControl': " + this);
        } else {
            controlResults.setError("Unknown operation name: " + name);
        }
        return controlResults;
    }
View Full Code Here

    public void shutdown() {
    }

    @Override
    public ControlResults invoke(String name, Configuration parameters) {
        ControlResults results = new ControlResults();

        try {
            if (CONTROL_CHECK_ALERTS_VALIDITY.equals(name)) {
                checkAlertsValidity(results);
            } else if (CONTROL_REASSIGN_ALERTS.equals(name)) {
                reassignAlerts(parameters);
            }
        } catch (Exception e) {
            results.setError(e);
        }

        return results;
    }
View Full Code Here

    public void shutdown() {
        System.out.println("The sample plugin has been shut down!!! : " + this);
    }

    public ControlResults invoke(String name, Configuration parameters) {
        ControlResults controlResults = new ControlResults();
        if (name.equals("testControl")) {
            String paramProp = parameters.getSimple("paramProp").getStringValue();
            if (paramProp.equals("fail")) {
                controlResults.setError("simulated failure!");
            } else {
                controlResults.getComplexResults().put(
                    new PropertySimple("resultProp", "the param was [" + paramProp + "]"));
            }
            System.out.println("Invoked 'testControl'!!! : " + this);
        } else if (name.equals("testControlWithNoParams")) {
            controlResults.getComplexResults().put(new PropertySimple("result", "results value"));
            System.out.println("Invoked 'testControlWithNoParams'!!! : " + this);
        } else if (name.equals("testControlWithNoParamsOrResults")) {
            System.out.println("Invoked 'testControlWithNoParamsOrResults'!!! : " + this);
        } else {
            controlResults.setError("Unknown operation name: " + name);
        }
        return controlResults;
    }
View Full Code Here

        log.debug("The RHQ AlertDefinition plugin has been shut down!!! : " + this);
    }

    @Override
    public ControlResults invoke(String name, Configuration parameters) {
        ControlResults controlResults = new ControlResults();

        try {
            if (name.equals("listInjectedAlertDefinitions")) {
                PropertyList result = new PropertyList("injectedAlertDefinitions");
                for (InjectedTemplate iad : injectedTemplates) {
                    PropertyMap map = new PropertyMap("injectedAlertDefinition");
                    map.put(new PropertySimple(InjectedTemplate.FIELD_PLUGIN_NAME, iad.getPluginName()));
                    map.put(new PropertySimple(InjectedTemplate.FIELD_RESOURCE_TYPE_NAME, iad.getResourceTypeName()));
                    map.put(new PropertySimple(InjectedTemplate.FIELD_NAME, iad.getName()));
                    map.put(new PropertySimple(InjectedTemplate.FIELD_DESCRIPTION, iad.getDescription()));
                    result.add(map);
                }
                controlResults.getComplexResults().put(result);

            } else if (name.equals("injectAllAlertDefinitions")) {
                injectAllAlertDefs(Boolean.valueOf(parameters.getSimpleValue("replaceIfExists")));

            } else if (name.equals("injectAlertDefinition")) {
                InjectedTemplate requestedInjection = new InjectedTemplate( //
                    parameters.getSimpleValue(InjectedTemplate.FIELD_PLUGIN_NAME), //
                    parameters.getSimpleValue(InjectedTemplate.FIELD_RESOURCE_TYPE_NAME), //
                    parameters.getSimpleValue(InjectedTemplate.FIELD_NAME), null);
                boolean injected = false;
                for (InjectedTemplate iad : injectedTemplates) {
                    if (iad.equals(requestedInjection)) {
                        injectAlertDef(iad, Boolean.valueOf(parameters.getSimpleValue("replaceIfExists", "false")));
                        injected = true;
                        break;
                    }
                }

                if (!injected) {
                    controlResults
                        .setError("Unknown requested alert definition. Check spelling: " + requestedInjection);
                }

            } else {
                controlResults.setError("Unknown control name: " + name);
            }
        } catch (Throwable t) {
            controlResults.setError(t);
        }

        return controlResults;
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.plugin.pc.ControlResults

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.