Search in sources :

Example 11 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project product-mi-tooling by wso2.

the class LoginDelegate method getTokenFromMI.

private String getTokenFromMI(String username, String password) throws ManagementApiException {
    GroupDelegate groupDelegate = new GroupDelegate();
    GroupList groupList = groupDelegate.getGroupList();
    if (groupList.isEmpty()) {
        logger.error("No running micro integrator instances found. Please start a server and login.");
        return "";
    } else {
        NodesDelegate nodesDelegate = new NodesDelegate();
        NodeList nodes = nodesDelegate.getNodes(groupList.get(0));
        return ManagementApiUtils.getToken(ManagementApiUtils.getMgtApiUrl(groupList.get(0), nodes.get(0).getNodeId()), username, password);
    }
}
Also used : GroupList(org.wso2.ei.dashboard.core.rest.model.GroupList) NodesDelegate(org.wso2.ei.dashboard.core.rest.delegates.nodes.NodesDelegate) NodeList(org.wso2.ei.dashboard.core.rest.model.NodeList) GroupDelegate(org.wso2.ei.dashboard.core.rest.delegates.groups.GroupDelegate)

Example 12 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project product-mi-tooling by wso2.

the class NodesDelegate method getNodes.

public NodeList getNodes(String groupId) {
    logger.debug("Fetching node list in " + groupId + " from database.");
    NodeList nodeList = databaseManager.fetchNodes(groupId);
    for (NodeListInner nodeListInner : nodeList) {
        String nodeId = nodeListInner.getNodeId();
        long heartbeatInterval = Long.parseLong(databaseManager.getHeartbeatInterval(groupId, nodeId));
        long lastTimestamp = Long.parseLong(databaseManager.retrieveTimestampOfLastHeartbeat(groupId, nodeId));
        long currentTimestamp = System.currentTimeMillis();
        // at least 1.5 * heartbeat_interval, the node will be denoted as unhealthy.
        if ((currentTimestamp - lastTimestamp) > heartbeatInterval * 1500) {
            nodeListInner.setStatus("unhealthy");
        } else {
            nodeListInner.setStatus("healthy");
        }
    }
    return nodeList;
}
Also used : NodeListInner(org.wso2.ei.dashboard.core.rest.model.NodeListInner) NodeList(org.wso2.ei.dashboard.core.rest.model.NodeList)

Example 13 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project product-mi-tooling by wso2.

the class JDBCDatabaseManager method getArtifactDetails.

private List<ArtifactDetails> getArtifactDetails(String getServicesQuery, String artifactName, String groupId, List<String> nodeList) {
    try (Connection con = getConnection();
        PreparedStatement statement = con.prepareStatement(getServicesQuery)) {
        statement.setString(1, artifactName);
        statement.setString(2, groupId);
        for (int i = 0, j = 3; i < nodeList.size(); i++, j++) {
            statement.setString(j, nodeList.get(i));
        }
        ResultSet resultSet = statement.executeQuery();
        List<ArtifactDetails> artifactDetailsList = new ArrayList<>();
        while (resultSet.next()) {
            ArtifactDetails artifactDetails = new ArtifactDetails();
            String nodeId = resultSet.getString("NODE_ID");
            String details = resultSet.getString("DETAILS");
            artifactDetails.setNodeId(nodeId);
            artifactDetails.setDetails(details);
            artifactDetailsList.add(artifactDetails);
        }
        return artifactDetailsList;
    } catch (SQLException e) {
        throw new DashboardServerException("Error occurred while retrieving next row.", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) ArtifactDetails(org.wso2.ei.dashboard.core.rest.model.ArtifactDetails) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Example 14 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project product-mi-tooling by wso2.

the class JDBCDatabaseManager method fetchNodes.

@Override
public NodeList fetchNodes(String groupId) {
    String query = "SELECT * FROM SERVERS WHERE GROUP_ID=?";
    try (Connection con = getConnection();
        PreparedStatement statement = con.prepareStatement(query)) {
        statement.setString(1, groupId);
        NodeList nodeList = new NodeList();
        ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
            String nodeId = resultSet.getString("NODE_ID");
            String details = resultSet.getString("DETAILS");
            NodeListInner nodeListInner = new NodeListInner();
            nodeListInner.setNodeId(nodeId);
            nodeListInner.setDetails(details);
            nodeList.add(nodeListInner);
        }
        return nodeList;
    } catch (SQLException e) {
        throw new DashboardServerException("Error occurred fetching servers.", e);
    }
}
Also used : NodeListInner(org.wso2.ei.dashboard.core.rest.model.NodeListInner) SQLException(java.sql.SQLException) NodeList(org.wso2.ei.dashboard.core.rest.model.NodeList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Example 15 with NodeList

use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-identity-framework by wso2.

the class AbstractPIPResourceFinder method findDescendantResources.

@Override
public Set<String> findDescendantResources(String parentResourceId, EvaluationCtx context) throws Exception {
    EvaluationResult environment;
    String environmentId = null;
    Set<String> resourceNames = null;
    NodeList children = context.getRequestRoot().getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child != null) {
            if (PDPConstants.ENVIRONMENT_ELEMENT.equals(child.getLocalName())) {
                if (child.getChildNodes() != null && child.getChildNodes().getLength() > 0) {
                    environment = context.getAttribute(new URI(StringAttribute.identifier), new URI(PDPConstants.ENVIRONMENT_ID_DEFAULT), null, new URI(XACMLConstants.ENT_CATEGORY));
                    if (environment != null && environment.getAttributeValue() != null && environment.getAttributeValue().isBag()) {
                        BagAttribute attr = (BagAttribute) environment.getAttributeValue();
                        environmentId = ((AttributeValue) attr.iterator().next()).encode();
                    }
                }
            }
        }
    }
    if (isAbstractResourceCacheEnabled) {
        IdentityCacheKey cacheKey;
        String key = PDPConstants.RESOURCE_DESCENDANTS + parentResourceId + (environmentId != null ? environmentId : "");
        tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        cacheKey = new IdentityCacheKey(tenantId, key);
        IdentityCacheEntry cacheEntry = (IdentityCacheEntry) abstractResourceCache.getValueFromCache(cacheKey);
        if (cacheEntry != null) {
            String[] values = cacheEntry.getCacheEntryArray();
            resourceNames = new HashSet<String>(Arrays.asList(values));
            if (log.isDebugEnabled()) {
                log.debug("Carbon Resource Cache Hit");
            }
        }
        if (resourceNames != null) {
            resourceNames = findDescendantResources(parentResourceId, environmentId);
            if (log.isDebugEnabled()) {
                log.debug("Carbon Resource Cache Miss");
            }
            if (resourceNames != null && !resourceNames.isEmpty()) {
                cacheEntry = new IdentityCacheEntry(resourceNames.toArray(new String[resourceNames.size()]));
                abstractResourceCache.addToCache(cacheKey, cacheEntry);
            }
        }
    } else {
        resourceNames = findDescendantResources(parentResourceId, environmentId);
    }
    return resourceNames;
}
Also used : IdentityCacheKey(org.wso2.carbon.identity.entitlement.cache.IdentityCacheKey) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IdentityCacheEntry(org.wso2.carbon.identity.entitlement.cache.IdentityCacheEntry) URI(java.net.URI) EvaluationResult(org.wso2.balana.cond.EvaluationResult) BagAttribute(org.wso2.balana.attr.BagAttribute)

Aggregations

NodeList (org.w3c.dom.NodeList)20 Element (org.w3c.dom.Element)12 Node (org.w3c.dom.Node)11 NodeList (org.wso2.ei.dashboard.core.rest.model.NodeList)10 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 JsonObject (com.google.gson.JsonObject)4 QName (javax.xml.namespace.QName)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 Document (org.w3c.dom.Document)4 NodeListInner (org.wso2.ei.dashboard.core.rest.model.NodeListInner)4 SAXException (org.xml.sax.SAXException)4 JsonElement (com.google.gson.JsonElement)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3