Search in sources :

Example 1 with TestParam

use of com.emc.vipr.model.sys.healthmonitor.TestParam in project coprhd-controller by CoprHD.

the class DiagnosticsExecTest method testNodeDiagnostics.

@Test
public void testNodeDiagnostics() {
    HealthMonitorService healthMonitorService = new HealthMonitorService();
    DiagnosticsRestRep resp = healthMonitorService.getDiagnostics(null, "1", null);
    Assert.assertNotNull(resp);
    Assert.assertNotNull(resp.getNodeDiagnosticsList());
    Set<String> testNames = new HashSet<String>();
    for (NodeDiagnostics diag : resp.getNodeDiagnosticsList()) {
        Assert.assertTrue(diag.getNodeId() != null && !diag.getNodeId().isEmpty());
        Assert.assertTrue(diag.getIp() != null && !diag.getIp().isEmpty());
        Assert.assertNotNull(diag.getDiagTests());
        for (DiagTest test : diag.getDiagTests()) {
            testNames.add(test.getName());
            Assert.assertTrue(test.getStatus() != null && !test.getStatus().isEmpty());
            if (test.getTestParams() != null) {
                for (TestParam param : test.getTestParams()) {
                    Assert.assertTrue(param.getKey() != null && !param.getKey().isEmpty());
                    Assert.assertTrue(param.getValue() != null && !param.getValue().isEmpty());
                }
            }
        }
        Assert.assertTrue(testNames.containsAll(DIAG_TESTS));
    }
}
Also used : HealthMonitorService(com.emc.storageos.systemservices.impl.resource.HealthMonitorService) TestParam(com.emc.vipr.model.sys.healthmonitor.TestParam) DiagnosticsRestRep(com.emc.vipr.model.sys.healthmonitor.DiagnosticsRestRep) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest) NodeDiagnostics(com.emc.vipr.model.sys.healthmonitor.NodeDiagnostics) HashSet(java.util.HashSet) Test(org.junit.Test) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest)

Example 2 with TestParam

use of com.emc.vipr.model.sys.healthmonitor.TestParam in project coprhd-controller by CoprHD.

the class DiagnosticsExec method convertStringToDiagTestList.

/**
 * Converts the diagtool output string to DiagTest objects.
 * Expected stdOut format when verbose option is set:
 * * Network routing: [OK]
 * network_gw=10.247.96.1
 * * DNS: [OK]
 * network_nameserver=10.254.66.23 [OK]
 * network_nameserver=10.254.66.24 [OK]
 * * Remote Repository: [OK]
 */
protected static List<DiagTest> convertStringToDiagTestList(String stdOut) {
    if (stdOut == null || stdOut.isEmpty()) {
        return null;
    }
    List<DiagTest> diagTests = new ArrayList<DiagTest>();
    Pattern paramValPattern = Pattern.compile("(.*)\\s+\\[(.*)\\]");
    Pattern testPattern = Pattern.compile("^\\*\\s+(\\S.*):\\s+\\[(.*)\\]");
    String[] tests = stdOut.split("\n");
    List<TestParam> paramStrs = null;
    for (String test : tests) {
        Matcher matcher = testPattern.matcher(test.trim());
        if (matcher.find()) {
            paramStrs = new ArrayList<TestParam>();
            diagTests.add(new DiagTest(matcher.group(1), matcher.group(2), paramStrs));
        } else {
            String[] keyVal = test.split("=");
            if (keyVal.length >= 2) {
                Matcher paramValMatcher = paramValPattern.matcher(keyVal[1]);
                if (paramValMatcher.find()) {
                    paramStrs.add(new TestParam(keyVal[0].trim(), paramValMatcher.group(1), paramValMatcher.group(2)));
                } else {
                    paramStrs.add(new TestParam(keyVal[0].trim(), keyVal[1]));
                }
            }
        }
    }
    return diagTests;
}
Also used : Pattern(java.util.regex.Pattern) TestParam(com.emc.vipr.model.sys.healthmonitor.TestParam) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest)

Example 3 with TestParam

use of com.emc.vipr.model.sys.healthmonitor.TestParam in project coprhd-controller by CoprHD.

the class HealthMonitorService method getDiagnostics.

/**
 * Get results of diagtool shell script for all virtual machines in a ViPR
 * controller appliance. Also gives test details when verbose option
 * is set.
 *
 * @brief Get diagtool script results
 * @param nodeIds node ids for which diagnostic results are collected.
 * @param nodeNames node names for which diagnostic results are collected.
 * @param verbose when set to "1"  will run command with -v option.
 * @prereq none
 * @return Returns diagnostic test results.
 */
@GET
@Path("/diagnostics")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public DiagnosticsRestRep getDiagnostics(@QueryParam("node_id") List<String> nodeIds, @QueryParam("verbose") String verbose, @QueryParam("node_name") List<String> nodeNames) {
    _log.info("Initiating diagnostics test for nodes");
    nodeIds = _coordinatorClientExt.combineNodeNamesWithNodeIds(nodeNames, nodeIds);
    boolean isVerbose = ("1".equals(verbose)) ? true : false;
    DiagRequestParams diagRequestParams = new DiagRequestParams(isVerbose);
    DiagnosticsRestRep diagnosticsRestRep = new DiagnosticsRestRep();
    List<NodeInfo> nodeInfoList = ClusterNodesUtil.getClusterNodeInfo(nodeIds);
    Map<String, NodeDiagnostics> nodesData = NodeDataCollector.getDataFromNodes(nodeInfoList, INTERNAL_NODE_DIAGNOSTICS_URI, Action.POST, diagRequestParams, NodeDiagnostics.class, null);
    String allocationResult = _checker.getNodeResourceAllocationCheckResult();
    DiagTest allocationTest = new DiagTest("Resource allocation", allocationResult, new ArrayList<TestParam>());
    for (Map.Entry<String, NodeDiagnostics> entry : nodesData.entrySet()) {
        List<DiagTest> diagTests = entry.getValue().getDiagTests();
        diagTests.add(allocationTest);
        entry.getValue().setDiagTests(diagTests);
    }
    diagnosticsRestRep.getNodeDiagnosticsList().addAll(nodesData.values());
    return diagnosticsRestRep;
}
Also used : TestParam(com.emc.vipr.model.sys.healthmonitor.TestParam) DiagRequestParams(com.emc.vipr.model.sys.healthmonitor.DiagRequestParams) DiagTest(com.emc.vipr.model.sys.healthmonitor.DiagTest) NodeInfo(com.emc.storageos.systemservices.impl.resource.util.NodeInfo) DiagnosticsRestRep(com.emc.vipr.model.sys.healthmonitor.DiagnosticsRestRep) NodeDiagnostics(com.emc.vipr.model.sys.healthmonitor.NodeDiagnostics) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

DiagTest (com.emc.vipr.model.sys.healthmonitor.DiagTest)3 TestParam (com.emc.vipr.model.sys.healthmonitor.TestParam)3 DiagnosticsRestRep (com.emc.vipr.model.sys.healthmonitor.DiagnosticsRestRep)2 NodeDiagnostics (com.emc.vipr.model.sys.healthmonitor.NodeDiagnostics)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 HealthMonitorService (com.emc.storageos.systemservices.impl.resource.HealthMonitorService)1 NodeInfo (com.emc.storageos.systemservices.impl.resource.util.NodeInfo)1 DiagRequestParams (com.emc.vipr.model.sys.healthmonitor.DiagRequestParams)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Test (org.junit.Test)1