Example usage for com.google.common.collect HashBasedTable create

List of usage examples for com.google.common.collect HashBasedTable create

Introduction

In this page you can find the example usage for com.google.common.collect HashBasedTable create.

Prototype

public static <R, C, V> HashBasedTable<R, C, V> create() 

Source Link

Document

Creates an empty HashBasedTable .

Usage

From source file:lcmc.crm.domain.CrmXml.java

/** Returns CibQuery object with information from the cib node. */
CibQuery parseCibQuery(final String query) {
    final Document document = XMLTools.getXMLDocument(query);
    final CibQuery cibQueryData = new CibQuery();
    if (document == null) {
        LOG.appWarning("parseCibQuery: cib error: " + query);
        return cibQueryData;
    }// w  ww .  j a va2  s . c o m
    /* get root <pacemaker> */
    final Node pcmkNode = XMLTools.getChildNode(document, "pcmk");
    if (pcmkNode == null) {
        LOG.appWarning("parseCibQuery: there is no pcmk node");
        return cibQueryData;
    }

    /* get fenced nodes */
    final Set<String> fencedNodes = new HashSet<String>();
    final Node fencedNode = XMLTools.getChildNode(pcmkNode, "fenced");
    if (fencedNode != null) {
        final NodeList nodes = fencedNode.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            final Node hostNode = nodes.item(i);
            if (hostNode.getNodeName().equals("node")) {
                final String h = XMLTools.getText(hostNode);
                if (h != null) {
                    fencedNodes.add(h.toLowerCase(Locale.US));
                }
            }
        }
    }

    /* get <cib> */
    final Node cibNode = XMLTools.getChildNode(pcmkNode, "cib");
    if (cibNode == null) {
        LOG.appWarning("parseCibQuery: there is no cib node");
        return cibQueryData;
    }
    /* Designated Co-ordinator */
    final String dcUuid = XMLTools.getAttribute(cibNode, "dc-uuid");
    //TODO: more attributes are here

    /* <configuration> */
    final Node confNode = XMLTools.getChildNode(cibNode, "configuration");
    if (confNode == null) {
        LOG.appWarning("parseCibQuery: there is no configuration node");
        return cibQueryData;
    }

    /* <rsc_defaults> */
    final Node rscDefaultsNode = XMLTools.getChildNode(confNode, "rsc_defaults");
    String rscDefaultsId = null;
    final Map<String, String> rscDefaultsParams = new HashMap<String, String>();
    final Map<String, String> rscDefaultsParamsNvpairIds = new HashMap<String, String>();
    if (rscDefaultsNode != null) {
        rscDefaultsId = parseResourceDefaults(rscDefaultsNode, rscDefaultsParams, rscDefaultsParamsNvpairIds);
    }

    /* <op_defaults> */
    final Node opDefaultsNode = XMLTools.getChildNode(confNode, "op_defaults");
    final Map<String, Value> opDefaultsParams = new HashMap<String, Value>();
    if (opDefaultsNode != null) {
        parseOpDefaults(opDefaultsNode, opDefaultsParams);
    }

    /* <crm_config> */
    final Node crmConfNode = XMLTools.getChildNode(confNode, "crm_config");
    if (crmConfNode == null) {
        LOG.appWarning("parseCibQuery: there is no crm_config node");
        return cibQueryData;
    }

    /*      <cluster_property_set> */
    final Node cpsNode = XMLTools.getChildNode(crmConfNode, "cluster_property_set");
    if (cpsNode == null) {
        LOG.appWarning("parseCibQuery: there is no cluster_property_set node");
    } else {
        final NodeList nvpairs;
        if (Tools.versionBeforePacemaker(host)) {
            /* <attributtes> only til 2.1.4 */
            final Node attrNode = XMLTools.getChildNode(cpsNode, "attributes");
            nvpairs = attrNode.getChildNodes();
        } else {
            nvpairs = cpsNode.getChildNodes();
        }
        final Map<String, String> crmConfMap = new HashMap<String, String>();
        /*              <nvpair...> */
        for (int i = 0; i < nvpairs.getLength(); i++) {
            final Node optionNode = nvpairs.item(i);
            if (optionNode.getNodeName().equals("nvpair")) {
                final String name = XMLTools.getAttribute(optionNode, "name");
                final String value = XMLTools.getAttribute(optionNode, "value");
                crmConfMap.put(name, value);
            }
        }
        cibQueryData.setCrmConfig(crmConfMap);
    }

    /* <nodes> */
    /* xml node with cluster node make stupid variable names, but let's
    * keep the convention. */
    String dc = null;
    final Table<String, String, String> nodeParametersMap = HashBasedTable.create();
    final Node nodesNode = XMLTools.getChildNode(confNode, "nodes");
    final Map<String, String> nodeOnline = new HashMap<String, String>();
    final Map<String, String> nodeID = new HashMap<String, String>();
    if (nodesNode != null) {
        final NodeList nodes = nodesNode.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            final Node nodeNode = nodes.item(i);
            if (nodeNode.getNodeName().equals("node")) {
                /* TODO: doing nothing with the info, just getting the dc,
                * for now.
                */
                final String id = XMLTools.getAttribute(nodeNode, "id");
                final String uname = XMLTools.getAttribute(nodeNode, "uname");
                if (!nodeID.containsKey(uname)) {
                    nodeID.put(uname, id);
                }
                if (dcUuid != null && dcUuid.equals(id)) {
                    dc = uname;
                }
                parseNode(uname, nodeNode, nodeParametersMap);
                if (!nodeOnline.containsKey(uname.toLowerCase(Locale.US))) {
                    nodeOnline.put(uname.toLowerCase(Locale.US), "no");
                }
            }
        }
    }

    /* <resources> */
    final Node resourcesNode = XMLTools.getChildNode(confNode, "resources");
    if (resourcesNode == null) {
        LOG.appWarning("parseCibQuery: there is no resources node");
        return cibQueryData;
    }
    /*      <primitive> */
    final Map<String, Map<String, String>> parametersMap = new HashMap<String, Map<String, String>>();
    final Map<String, Map<String, String>> parametersNvpairsIdsMap = new HashMap<String, Map<String, String>>();
    final Map<String, ResourceAgent> resourceTypeMap = new HashMap<String, ResourceAgent>();
    final Set<String> orphanedList = new HashSet<String>();
    /* host -> inLRMList list */
    final Map<String, Set<String>> inLRMList = new HashMap<String, Set<String>>();
    final Map<String, String> resourceInstanceAttrIdMap = new HashMap<String, String>();
    final MultiKeyMap<String, Value> operationsMap = new MultiKeyMap<String, Value>();
    final Map<String, String> metaAttrsIdMap = new HashMap<String, String>();
    final Map<String, String> operationsIdMap = new HashMap<String, String>();
    final Map<String, Map<String, String>> resOpIdsMap = new HashMap<String, Map<String, String>>();
    /* must be linked, so that clone from group is before the group itself.
    */
    final Map<String, List<String>> groupsToResourcesMap = new LinkedHashMap<String, List<String>>();
    final Map<String, String> cloneToResourceMap = new HashMap<String, String>();
    final List<String> masterList = new ArrayList<String>();
    final Table<String, String, String> failedMap = HashBasedTable.create();
    final Table<String, String, Set<String>> failedClonesMap = HashBasedTable.create();
    final Map<String, String> pingCountMap = new HashMap<String, String>();
    groupsToResourcesMap.put("none", new ArrayList<String>());

    final NodeList primitivesGroups = resourcesNode.getChildNodes();
    final Map<String, String> operationsIdRefs = new HashMap<String, String>();
    final Map<String, String> operationsIdtoCRMId = new HashMap<String, String>();
    final Map<String, String> metaAttrsIdRefs = new HashMap<String, String>();
    final Map<String, String> metaAttrsIdToCRMId = new HashMap<String, String>();
    for (int i = 0; i < primitivesGroups.getLength(); i++) {
        final Node primitiveGroupNode = primitivesGroups.item(i);
        final String nodeName = primitiveGroupNode.getNodeName();
        if ("primitive".equals(nodeName)) {
            final List<String> resList = groupsToResourcesMap.get("none");
            parsePrimitiveNode(primitiveGroupNode, resList, resourceTypeMap, parametersMap,
                    parametersNvpairsIdsMap, resourceInstanceAttrIdMap, operationsMap, metaAttrsIdMap,
                    operationsIdMap, resOpIdsMap, operationsIdRefs, operationsIdtoCRMId, metaAttrsIdRefs,
                    metaAttrsIdToCRMId);
        } else if ("group".equals(nodeName)) {
            parseGroupNode(primitiveGroupNode, null, groupsToResourcesMap, parametersMap, resourceTypeMap,
                    parametersNvpairsIdsMap, resourceInstanceAttrIdMap, operationsMap, metaAttrsIdMap,
                    operationsIdMap, resOpIdsMap, operationsIdRefs, operationsIdtoCRMId, metaAttrsIdRefs,
                    metaAttrsIdToCRMId);
        } else if ("master".equals(nodeName) || "master_slave".equals(nodeName) || "clone".equals(nodeName)) {
            final NodeList primitives = primitiveGroupNode.getChildNodes();
            final String cloneId = XMLTools.getAttribute(primitiveGroupNode, "id");
            List<String> resList = groupsToResourcesMap.get(cloneId);
            if (resList == null) {
                resList = new ArrayList<String>();
                groupsToResourcesMap.put(cloneId, resList);
            }
            parseAttributes(primitiveGroupNode, cloneId, parametersMap, parametersNvpairsIdsMap,
                    resourceInstanceAttrIdMap, operationsMap, metaAttrsIdMap, operationsIdMap, resOpIdsMap,
                    operationsIdRefs, operationsIdtoCRMId, metaAttrsIdRefs, metaAttrsIdToCRMId, false);
            for (int j = 0; j < primitives.getLength(); j++) {
                final Node primitiveNode = primitives.item(j);
                if (primitiveNode.getNodeName().equals("primitive")) {
                    parsePrimitiveNode(primitiveNode, resList, resourceTypeMap, parametersMap,
                            parametersNvpairsIdsMap, resourceInstanceAttrIdMap, operationsMap, metaAttrsIdMap,
                            operationsIdMap, resOpIdsMap, operationsIdRefs, operationsIdtoCRMId,
                            metaAttrsIdRefs, metaAttrsIdToCRMId);
                } else if (primitiveNode.getNodeName().equals("group")) {
                    parseGroupNode(primitiveNode, resList, groupsToResourcesMap, parametersMap, resourceTypeMap,
                            parametersNvpairsIdsMap, resourceInstanceAttrIdMap, operationsMap, metaAttrsIdMap,
                            operationsIdMap, resOpIdsMap, operationsIdRefs, operationsIdtoCRMId,
                            metaAttrsIdRefs, metaAttrsIdToCRMId);
                }
            }
            if (!resList.isEmpty()) {
                cloneToResourceMap.put(cloneId, resList.get(0));
                if ("master".equals(nodeName) || "master_slave".equals(nodeName)) {
                    masterList.add(cloneId);
                }
            }
        }
    }

    /* operationsRefs crm id -> crm id */
    final Map<String, String> operationsRefs = new HashMap<String, String>();
    for (final String crmId : operationsIdRefs.keySet()) {
        final String idRef = operationsIdRefs.get(crmId);
        operationsRefs.put(crmId, operationsIdtoCRMId.get(idRef));
    }

    /* mettaAttrsRefs crm id -> crm id */
    final Map<String, String> metaAttrsRefs = new HashMap<String, String>();
    for (final String crmId : metaAttrsIdRefs.keySet()) {
        final String idRef = metaAttrsIdRefs.get(crmId);
        metaAttrsRefs.put(crmId, metaAttrsIdToCRMId.get(idRef));
    }

    /* <constraints> */
    final Map<String, ColocationData> colocationIdMap = new LinkedHashMap<String, ColocationData>();
    final Map<String, List<ColocationData>> colocationRscMap = new HashMap<String, List<ColocationData>>();
    final Map<String, OrderData> orderIdMap = new LinkedHashMap<String, OrderData>();
    final Map<String, List<RscSet>> orderIdRscSetsMap = new HashMap<String, List<RscSet>>();
    final Map<String, List<RscSet>> colocationIdRscSetsMap = new HashMap<String, List<RscSet>>();
    final List<RscSetConnectionData> rscSetConnections = new ArrayList<RscSetConnectionData>();
    final Map<String, List<OrderData>> orderRscMap = new HashMap<String, List<OrderData>>();
    final Map<String, Map<String, HostLocation>> locationMap = new HashMap<String, Map<String, HostLocation>>();
    final Map<String, HostLocation> pingLocationMap = new HashMap<String, HostLocation>();
    final Map<String, List<String>> locationsIdMap = new HashMap<String, List<String>>();
    final Table<String, String, String> resHostToLocIdMap = HashBasedTable.create();

    final Map<String, String> resPingToLocIdMap = new HashMap<String, String>();
    final Node constraintsNode = XMLTools.getChildNode(confNode, "constraints");
    if (constraintsNode != null) {
        final NodeList constraints = constraintsNode.getChildNodes();
        String rscString = "rsc";
        String rscRoleString = "rsc-role";
        String withRscString = "with-rsc";
        String withRscRoleString = "with-rsc-role";
        String firstString = "first";
        String thenString = "then";
        String firstActionString = "first-action";
        String thenActionString = "then-action";
        if (Tools.versionBeforePacemaker(host)) {
            rscString = "from";
            rscRoleString = "from_role";
            withRscString = "to";
            withRscRoleString = "to_role";
            firstString = "to";
            thenString = "from";
            firstActionString = "to_action";
            thenActionString = "action";
        }
        for (int i = 0; i < constraints.getLength(); i++) {
            final Node constraintNode = constraints.item(i);
            if (constraintNode.getNodeName().equals("rsc_colocation")) {
                final String colId = XMLTools.getAttribute(constraintNode, "id");
                final String rsc = XMLTools.getAttribute(constraintNode, rscString);
                final String withRsc = XMLTools.getAttribute(constraintNode, withRscString);
                if (rsc == null || withRsc == null) {
                    final List<RscSet> rscSets = new ArrayList<RscSet>();
                    parseResourceSets(constraintNode, colId, null, rscSets, rscSetConnections);
                    colocationIdRscSetsMap.put(colId, rscSets);
                }
                final String rscRole = XMLTools.getAttribute(constraintNode, rscRoleString);
                final String withRscRole = XMLTools.getAttribute(constraintNode, withRscRoleString);
                final String score = XMLTools.getAttribute(constraintNode, SCORE_CONSTRAINT_PARAM);
                final ColocationData colocationData = new ColocationData(colId, rsc, withRsc, rscRole,
                        withRscRole, score);
                colocationIdMap.put(colId, colocationData);
                List<ColocationData> withs = colocationRscMap.get(rsc);
                if (withs == null) {
                    withs = new ArrayList<ColocationData>();
                }
                withs.add(colocationData);
                colocationRscMap.put(rsc, withs);
            } else if (constraintNode.getNodeName().equals("rsc_order")) {
                String rscFirst = XMLTools.getAttribute(constraintNode, firstString);
                String rscThen = XMLTools.getAttribute(constraintNode, thenString);
                final String ordId = XMLTools.getAttribute(constraintNode, "id");
                if (rscFirst == null || rscThen == null) {
                    final List<RscSet> rscSets = new ArrayList<RscSet>();
                    parseResourceSets(constraintNode, null, ordId, rscSets, rscSetConnections);
                    orderIdRscSetsMap.put(ordId, rscSets);
                }
                final String score = XMLTools.getAttribute(constraintNode, SCORE_CONSTRAINT_PARAM);
                final String symmetrical = XMLTools.getAttribute(constraintNode, "symmetrical");
                String firstAction = XMLTools.getAttribute(constraintNode, firstActionString);
                String thenAction = XMLTools.getAttribute(constraintNode, thenActionString);
                final String type = XMLTools.getAttribute(constraintNode, "type");
                if (type != null && "before".equals(type)) {
                    /* exchange resoruces */
                    final String rsc = rscFirst;
                    rscFirst = rscThen;
                    rscThen = rsc;
                    final String act = firstAction;
                    firstAction = thenAction;
                    thenAction = act;
                }
                final OrderData orderData = new OrderData(ordId, rscFirst, rscThen, score, symmetrical,
                        firstAction, thenAction);
                orderIdMap.put(ordId, orderData);
                List<OrderData> thens = orderRscMap.get(rscFirst);
                if (thens == null) {
                    thens = new ArrayList<OrderData>();
                }
                thens.add(orderData);
                orderRscMap.put(rscFirst, thens);
            } else if ("rsc_location".equals(constraintNode.getNodeName())) {
                final String locId = XMLTools.getAttribute(constraintNode, "id");
                final String node = XMLTools.getAttribute(constraintNode, "node");
                final String rsc = XMLTools.getAttribute(constraintNode, "rsc");
                final String score = XMLTools.getAttribute(constraintNode, SCORE_CONSTRAINT_PARAM);

                List<String> locs = locationsIdMap.get(rsc);
                if (locs == null) {
                    locs = new ArrayList<String>();
                    locationsIdMap.put(rsc, locs);
                }
                Map<String, HostLocation> hostScoreMap = locationMap.get(rsc);
                if (hostScoreMap == null) {
                    hostScoreMap = new HashMap<String, HostLocation>();
                    locationMap.put(rsc, hostScoreMap);
                }
                final String role = null; // TODO
                if (node != null) {
                    resHostToLocIdMap.put(rsc, node.toLowerCase(Locale.US), locId);
                    if (score != null) {
                        hostScoreMap.put(node.toLowerCase(Locale.US),
                                new HostLocation(score, "eq", null, role));
                    }
                }
                locs.add(locId);
                final Node ruleNode = XMLTools.getChildNode(constraintNode, "rule");
                if (ruleNode != null) {
                    final String score2 = XMLTools.getAttribute(ruleNode, SCORE_CONSTRAINT_PARAM);
                    final String booleanOp = XMLTools.getAttribute(ruleNode, "boolean-op");
                    // TODO: I know only "and", ignoring everything we
                    // don't know.
                    final Node expNode = XMLTools.getChildNode(ruleNode, "expression");
                    if (expNode != null && "expression".equals(expNode.getNodeName())) {
                        final String attr = XMLTools.getAttribute(expNode, "attribute");
                        final String op = XMLTools.getAttribute(expNode, "operation");
                        final String value = XMLTools.getAttribute(expNode, "value");
                        if ((booleanOp == null || "and".equals(booleanOp)) && "#uname".equals(attr)
                                && value != null) {
                            hostScoreMap.put(value.toLowerCase(Locale.US),
                                    new HostLocation(score2, op, null, role));
                            resHostToLocIdMap.put(rsc, value.toLowerCase(Locale.US), locId);
                        } else if ((booleanOp == null || "and".equals(booleanOp)) && "pingd".equals(attr)) {
                            pingLocationMap.put(rsc, new HostLocation(score2, op, value, null));
                            resPingToLocIdMap.put(rsc, locId);
                        } else {
                            LOG.appWarning("parseCibQuery: could not parse rsc_location: " + locId);
                        }
                    }
                }
            }
        }
    }

    /* <status> */
    final Node statusNode = XMLTools.getChildNode(cibNode, "status");
    final Set<String> nodePending = new HashSet<String>();
    if (statusNode != null) {
        /* <node_state ...> */
        final NodeList nodes = statusNode.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            final Node nodeStateNode = nodes.item(i);
            if ("node_state".equals(nodeStateNode.getNodeName())) {
                final String uname = XMLTools.getAttribute(nodeStateNode, "uname");
                final String id = XMLTools.getAttribute(nodeStateNode, "id");
                if (uname == null || !id.equals(nodeID.get(uname))) {
                    LOG.appWarning("parseCibQuery: skipping " + uname + ' ' + id);
                    continue;
                }
                final String join = XMLTools.getAttribute(nodeStateNode, "join");
                final String inCCM = XMLTools.getAttribute(nodeStateNode, "in_ccm");
                final String crmd = XMLTools.getAttribute(nodeStateNode, "crmd");
                if ("member".equals(join) && "true".equals(inCCM) && !"offline".equals(crmd)) {
                    nodeOnline.put(uname.toLowerCase(Locale.US), "yes");
                } else {
                    nodeOnline.put(uname.toLowerCase(Locale.US), "no");
                }
                if ("pending".equals(join)) {
                    nodePending.add(uname.toLowerCase(Locale.US));
                }
                final NodeList nodeStates = nodeStateNode.getChildNodes();
                /* transient attributes. */
                for (int j = 0; j < nodeStates.getLength(); j++) {
                    final Node nodeStateChild = nodeStates.item(j);
                    if ("transient_attributes".equals(nodeStateChild.getNodeName())) {
                        parseTransientAttributes(uname, nodeStateChild, failedMap, failedClonesMap,
                                pingCountMap);
                    }
                }
                final List<String> resList = groupsToResourcesMap.get("none");
                for (int j = 0; j < nodeStates.getLength(); j++) {
                    final Node nodeStateChild = nodeStates.item(j);
                    if ("lrm".equals(nodeStateChild.getNodeName())) {
                        parseLrmResources(uname.toLowerCase(Locale.US), nodeStateChild, resList,
                                resourceTypeMap, parametersMap, inLRMList, orphanedList, failedClonesMap);
                    }
                }
            }
        }
    }
    cibQueryData.setDC(dc);
    cibQueryData.setNodeParameters(nodeParametersMap);
    cibQueryData.setResourceParameters(parametersMap);
    cibQueryData.setResourceParametersNvpairsIds(parametersNvpairsIdsMap);
    cibQueryData.setResourceType(resourceTypeMap);
    cibQueryData.setInLRM(inLRMList);
    cibQueryData.setOrphaned(orphanedList);
    cibQueryData.setResourceInstanceAttrId(resourceInstanceAttrIdMap);

    cibQueryData.setColocationRsc(colocationRscMap);
    cibQueryData.setColocationId(colocationIdMap);

    cibQueryData.setOrderId(orderIdMap);
    cibQueryData.setOrderIdRscSets(orderIdRscSetsMap);
    cibQueryData.setColocationIdRscSets(colocationIdRscSetsMap);
    cibQueryData.setRscSetConnections(rscSetConnections);
    cibQueryData.setOrderRsc(orderRscMap);

    cibQueryData.setLocations(locationMap);
    cibQueryData.setPingLocations(pingLocationMap);
    cibQueryData.setLocationsId(locationsIdMap);
    cibQueryData.setResHostToLocId(resHostToLocIdMap);
    cibQueryData.setResPingToLocId(resPingToLocIdMap);
    cibQueryData.setOperations(operationsMap);
    cibQueryData.setOperationsId(operationsIdMap);
    cibQueryData.setOperationsRefs(operationsRefs);
    cibQueryData.setMetaAttrsId(metaAttrsIdMap);
    cibQueryData.setMetaAttrsRefs(metaAttrsRefs);
    cibQueryData.setResOpIds(resOpIdsMap);
    cibQueryData.setNodeOnline(nodeOnline);
    cibQueryData.setNodePending(nodePending);
    cibQueryData.setGroupsToResources(groupsToResourcesMap);
    cibQueryData.setCloneToResource(cloneToResourceMap);
    cibQueryData.setMasterList(masterList);
    cibQueryData.setNodeFailedCount(failedMap);
    cibQueryData.setResourceFailedCloneIds(failedClonesMap);
    cibQueryData.setNodePingCount(pingCountMap);
    cibQueryData.setRscDefaultsId(rscDefaultsId);
    cibQueryData.setRscDefaultsParams(rscDefaultsParams);
    cibQueryData.setRscDefaultsParamsNvpairIds(rscDefaultsParamsNvpairIds);
    cibQueryData.setOpDefaultsParams(opDefaultsParams);
    cibQueryData.setFencedNodes(fencedNodes);
    return cibQueryData;
}