Examples of OperationResult


Examples of org.rhq.core.pluginapi.operation.OperationResult

        ResourceComponent resourceComponent = PluginContainer.getInstance().getInventoryManager()
            .getResourceComponent(resource);

        if (resourceComponent instanceof OperationFacet) {
            try {
                OperationResult result = ((OperationFacet) resourceComponent).invokeOperation("enableContext", null);
                log.info("Result of operation " + "enableContext" + " was: " + result.getSimpleResult());

                Configuration config = new Configuration();
                config.put(new PropertySimple("timeout", "1"));
                config.put(new PropertySimple("unit", java.util.concurrent.TimeUnit.SECONDS));

                result = ((OperationFacet) resourceComponent).invokeOperation("stopContext", config);
                log.info("Result of operation stopContext was: " + result.getSimpleResult());
                assert result.getSimpleResult().equals("true") : "The operation execution failed!";

                result = ((OperationFacet) resourceComponent).invokeOperation("enableContext", null);
                log.info("Result of operation enableContext was: " + result.getSimpleResult());
                assert result.getSimpleResult().equals("true") : "The operation execution failed!";

                result = ((OperationFacet) resourceComponent).invokeOperation("disableContext", null);
                log.info("Result of operation disableContext was: " + result.getSimpleResult());
                assert result.getSimpleResult().equals("true") : "The operation execution failed!";
            } catch (Exception e) {
                log.info("Operation failed. ", e);
            }

        }
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

    public void invokeOperation(ExpectedApacheState desiredState, String operation) throws Exception {
        int i = 0;

        while (i < 10) {
            OperationResult res = serverComponent.invokeOperation(operation, new Configuration());

            LOG.debug("Invoked operation '" + operation + "' on " + resourceContext.getResourceKey() + " (waiting for "
                + desiredState + "), attempt " + i + ": " + res.getComplexResults().getMap().toString());

            //wait for max 30s for the operation to "express" itself
            int w = 0;
            ProcessInfo pi;
            while (w < 30) {
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

        return listOfSnapshots;
    }

    private OperationResult restoreSnapshot(Configuration parameters) {
        OperationResult result = new OperationResult();

        //1. Find the list of snapshots discovered
        String requestedSnapshotName = parameters.getSimpleValue("snapshotName");
        PropertyList listOfSnapShots = this.getSnapshotsWithDetails();

        String snapshotDirectoryName = null;
        for (Property property : listOfSnapShots.getList()) {
            String snapshotName = ((PropertyMap) property).getSimpleValue("name", null);
            if (requestedSnapshotName.equals(snapshotName)) {
                snapshotDirectoryName = ((PropertyMap) property).getSimpleValue("folder", null);
                break;
            }
        }

        //2. Find out if the discovered snapshot still exists on disk
        if (snapshotDirectoryName == null) {
            result.setErrorMessage("Restore failed! The snapshot does not exist!");
            return result;
        }

        File snapshotDirectory = new File(snapshotDirectoryName);
        if (!snapshotDirectory.exists() || !snapshotDirectory.isDirectory()) {
            result.setErrorMessage("Restore failed! The snapshot does not exist on disk!");
            return result;
        }

        //3. Shutdown Cassandra
        CassandraNodeComponent node = this.getParentKeyspace().getCassandraNodeComponent();
        node.shutdownNode();

        //4. Remove the entire commit log
        KeyspaceComponent parentKeyspace = this.getParentKeyspace();

        parentKeyspace.clearCommitLog();

        //5. Copy the snapshot files to the column family folders
        PropertyList parentDataFileLocations = parentKeyspace.getKeySpaceDataFileLocations();

        for (Property dataFileDirectoryProperty : parentDataFileLocations.getList()) {
            String columnFamilyDirectoryName = ((PropertySimple) dataFileDirectoryProperty).getStringValue();
            columnFamilyDirectoryName += "/" + this.getResourceContext().getPluginConfiguration().getSimpleValue("name");

            File columnFamilyDirectory = new File(columnFamilyDirectoryName);
            if(columnFamilyDirectory.exists()){
                //5.1 Remove existing data files
                File[] originalColumnFamilyDataFiles = columnFamilyDirectory.listFiles();
                if (originalColumnFamilyDataFiles != null) {
                    for (File file : originalColumnFamilyDataFiles) {
                        if (file.isFile()) {
                            file.delete();
                        }
                    }
                }

                //5.2 Copy snapshots files to column family folder
                File[] filesToBeRestored = snapshotDirectory.listFiles();
                if (filesToBeRestored != null) {
                    for (File fileToBeRestored : filesToBeRestored) {
                        if (fileToBeRestored.isFile()) {
                            File destinationFile = new File(columnFamilyDirectory, fileToBeRestored.getName());
                            try {
                                FileUtil.copyFile(fileToBeRestored, destinationFile);
                            } catch (Exception e) {
                                result.setErrorMessage("Restore failed! The file copying process failed!");
                                return result;
                            }
                        }
                    }
                }
            }
        }

        //6. Restart Cassandra
        node.startNode();

        result.setSimpleResult("Snapshot restored succesfully...");

        return result;
    }
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

            // Make roughly 1 out of 10 invocations fail.
            if ((RANDOM.nextInt(10) % 9) == 0) {
                throw new Exception("Operation failed!");
            } else {
                // Assume the operation returns an empty result config.
                return new OperationResult();
            }
        }
    }
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

            }
        }
    }

    private OperationResult createEvents(Configuration params) {
        OperationResult result;

        int count = params.getSimple("count").getIntegerValue();
        String source = params.getSimple("source").getStringValue();
        String details = params.getSimple("details").getStringValue();
        String eventType = resourceContext.getResourceType().getName() + "-event";
        String severityArg = params.getSimple("severity").getStringValue();
        EventSeverity severity;

        try {
            severity = EventSeverity.valueOf(severityArg);
        } catch (IllegalArgumentException e) {
            result = new OperationResult("passed");
            result.setErrorMessage(severityArg + " - illegal value for severity. Supported values are " +
                Arrays.toString(EventSeverity.values()));

            return result;
        }


        EventContext eventContext = resourceContext.getEventContext();

        for (int i = 0; i < count; ++i) {
            Event event = new Event(eventType, source, System.currentTimeMillis(), severity, details);
            eventContext.publishEvent(event);
        }

        result = new OperationResult("failed");
        return result;
    }
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

    protected static final String PLUGINCONFIG_DETECTION_MECHANISM = "detectionMechanism"; // also used for operation results
    protected static final String PLUGINCONFIG_EXECUTABLE = ScriptServerComponent.PLUGINCONFIG_EXECUTABLE;

    @Override
    public OperationResult invokeOperation(String name, Configuration params) throws Exception {
        OperationResult result;

        if ("getNetworkConnections".equals(name)) {
            Configuration pluginConfiguration = getResourcContext().getPluginConfiguration();
            DetectionMechanism mechanism = LsofDiscoveryComponent.getDetectionMechanism(pluginConfiguration);

            if (mechanism == DetectionMechanism.EXTERNAL) {
                log.info("Getting network connections using the external mechanism");

                // compile the regex that will be used to parse the output
                String regex = params.getSimpleValue("regex", "");
                if (regex.length() == 0) {
                    throw new Exception("missing regex parameter");
                }
                Pattern pattern = Pattern.compile(regex);

                // first run the executable
                OperationResult intermediaryResult = super.invokeOperation(name, params);
                Configuration intermediaryConfig = intermediaryResult.getComplexResults();

                // now build our results object
                result = new OperationResult();
                Configuration config = result.getComplexResults();
                config.put(new PropertySimple("detectionMechanism", mechanism.toString()));
                config.put(intermediaryConfig.getSimple(OPERATION_RESULT_EXITCODE));
                if (intermediaryResult.getErrorMessage() != null) {
                    result.setErrorMessage(intermediaryResult.getErrorMessage());
                } else {
                    String output = intermediaryConfig.getSimpleValue(OPERATION_RESULT_OUTPUT, "");
                    if (output.length() > 0) {
                        PropertyList list = new PropertyList("networkConnections");
                        config.put(list);

                        String[] lines = output.split("\n");
                        for (String line : lines) {
                            Matcher matcher = pattern.matcher(line);
                            if (matcher.matches()) {
                                PropertyMap map = new PropertyMap("networkConnection");
                                list.add(map);
                                map.put(new PropertySimple("localHost", matcher.group(1)));
                                map.put(new PropertySimple("localPort", matcher.group(2)));
                                map.put(new PropertySimple("remoteHost", matcher.group(3)));
                                map.put(new PropertySimple("remotePort", matcher.group(4)));
                            }
                        }
                    }
                }
            } else {
                log.info("Getting network connections using the internal mechanism");
                result = new OperationResult();
                Configuration config = result.getComplexResults();
                config.put(new PropertySimple("detectionMechanism", mechanism.toString()));

                try {
                    List<NetConnection> conns;
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

        }
    }

    public OperationResult invokeOperation(String name, Configuration params) throws Exception {

        OperationResult result = null;

        if (name.equals("join")) {
            result = updateSmbAds(params);
        } else if (name.equals("disconnect")) {
            result = disconnectSmbAds(params);
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

    }

    private OperationResult disconnectSmbAds(Configuration params) throws Exception {

        Configuration resourceConfig = this.loadResourceConfiguration();
        OperationResult result = new OperationResult();

        String username = resourceConfig.getSimple("username").getStringValue();
        String password = resourceConfig.getSimple("password").getStringValue();

        if (username == null || password == null) {
            result.setSimpleResult("Missing required connection parameters");
            return result;
        }

        StringBuilder netArgs = new StringBuilder();
        netArgs.append("ads leave");
        netArgs.append(SPACE + "-U " + username + "%" + password);

        ProcessExecutionResults netResults = execute(NET_PATH, netArgs.toString());
        String results = netResults.getCapturedOutput();

        result.setSimpleResult(results);

        return result;
    }
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

    }

    private OperationResult updateSmbAds(Configuration params) throws Exception {

        Configuration resourceConfig = this.loadResourceConfiguration();
        OperationResult result = new OperationResult();

        String realm = resourceConfig.getSimple("realm").getStringValue();
        String controller = resourceConfig.getSimple("controller").getStringValue();
        String username = resourceConfig.getSimple("username").getStringValue();
        String password = resourceConfig.getSimple("password").getStringValue();
        String workgroup = resourceConfig.getSimple("workgroup").getStringValue();
        String idmapuid = resourceConfig.getSimple("idmap uid").getStringValue();
        String idmapgid = resourceConfig.getSimple("idmap gid").getStringValue();
        String shell = resourceConfig.getSimple("template shell").getStringValue();

        if (realm == null || controller == null || username == null || password == null || workgroup == null) {
            result.setSimpleResult("Missing required connection parameters");
            return result;
        }

        StringBuilder authArgs = new StringBuilder();
        StringBuilder netArgs = new StringBuilder();

        // AuthConfig arguments...ugly and would be a lot prettier using python
        authArgs.append("--smbservers=" + controller);
        authArgs.append(SPACE + "--smbrealm=" + realm);
        authArgs.append(SPACE + "--enablewinbind --smbsecurity=ads");

        if (idmapuid != null) {
            authArgs.append(SPACE + "--smbidmapuid=" + idmapuid);
        }

        if (idmapgid != null) {
            authArgs.append(SPACE + "--smbidmapgid=" + idmapgid);
        }

        if (shell != null) {
            authArgs.append(SPACE + "--winbindtemplateshell=" + shell);
        }

        authArgs.append(SPACE + "--update");

        // Net join arguments
        netArgs.append("join");
        netArgs.append(SPACE + "-w " + workgroup);
        netArgs.append(SPACE + "-S " + controller);
        netArgs.append(SPACE + "-U " + username + "%" + password);

        ProcessExecutionResults authResults = execute(AUTHCONFIG_PATH, authArgs.toString());
        ProcessExecutionResults netResults = execute(NET_PATH, netArgs.toString());

        String results = authResults.getCapturedOutput() + netResults.getCapturedOutput();

        result.setSimpleResult(results);

        return result;
    }
View Full Code Here

Examples of org.rhq.core.pluginapi.operation.OperationResult

    }

    @Override
    public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
        if (name.equals("shutdown")) {
            OperationResult operationResult = shutdownNode();
            waitForNodeToGoDown();
            return operationResult;
        } else if (name.equals("start")) {
            return startNode();
        } else if (name.equals("restart")) {
            return restartNode();
        } else if (name.equals("updateSeedsList")) {
            return updateSeedsList(parameters);
        } else if (name.equals("takeSnapshot")) {
            if (isStorageServiceReachable()) {
                return new TakeSnapshotOperation(new KeyspaceService(getEmsConnection()), parameters).invoke();
            } else {
                OperationResult result = new OperationResult();
                result.setErrorMessage("Unable to take snaphost, Storage Node is not available");
                return result;
            }

        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.