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);
}
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations