From 87a58c0a6549656511bc35af6c77df0902cfddee Mon Sep 17 00:00:00 2001 From: pnguyen Date: Tue, 26 May 2009 11:48:41 -0700 Subject: [PATCH] [HQ-1665] Add ResourceEdgeApi --- src/org/hyperic/hq/hqapi1/HQApi.java | 11 ++ .../hyperic/hq/hqapi1/ResourceEdgeApi.java | 131 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 src/org/hyperic/hq/hqapi1/ResourceEdgeApi.java diff --git a/src/org/hyperic/hq/hqapi1/HQApi.java b/src/org/hyperic/hq/hqapi1/HQApi.java index c45aeb13..476b94df 100644 --- a/src/org/hyperic/hq/hqapi1/HQApi.java +++ b/src/org/hyperic/hq/hqapi1/HQApi.java @@ -44,6 +44,7 @@ public class HQApi { private final AgentApi _agentApi; private final AlertDefinitionApi _alertDefinitionApi; private final MaintenanceApi _maintenanceApi; + private final ResourceEdgeApi _resourceEdgeApi; /** * @param host The hostname of the HQ Server to connect to. @@ -66,6 +67,7 @@ public HQApi(String host, int port, boolean isSecure, String user, _agentApi = new AgentApi(connection); _alertDefinitionApi = new AlertDefinitionApi(connection); _maintenanceApi = new MaintenanceApi(connection); + _resourceEdgeApi = new ResourceEdgeApi(connection); } /** @@ -158,4 +160,13 @@ public AlertDefinitionApi getAlertDefinitionApi() { public MaintenanceApi getMaintenanceApi() { return _maintenanceApi; } + + /** + * List and update the relationships between resources. + * + * @return The API for operating on resource relationships. + */ + public ResourceEdgeApi getResourceEdgeApi() { + return _resourceEdgeApi; + } } diff --git a/src/org/hyperic/hq/hqapi1/ResourceEdgeApi.java b/src/org/hyperic/hq/hqapi1/ResourceEdgeApi.java new file mode 100644 index 00000000..c68b7085 --- /dev/null +++ b/src/org/hyperic/hq/hqapi1/ResourceEdgeApi.java @@ -0,0 +1,131 @@ +/* + * + * NOTE: This copyright does *not* cover user programs that use HQ + * program services by normal system calls through the application + * program interfaces provided as part of the Hyperic Plug-in Development + * Kit or the Hyperic Client Development Kit - this is merely considered + * normal use of the program, and does *not* fall under the heading of + * "derived work". + * + * Copyright (C) [2008, 2009], Hyperic, Inc. + * This file is part of HQ. + * + * HQ is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program is distributed + * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + */ + +package org.hyperic.hq.hqapi1; + +import org.hyperic.hq.hqapi1.types.ResponseStatus; +import org.hyperic.hq.hqapi1.types.StatusResponse; +import org.hyperic.hq.hqapi1.types.ResourceEdge; +import org.hyperic.hq.hqapi1.types.ResourceEdgesRequest; +import org.hyperic.hq.hqapi1.types.ResourceEdgesResponse; +import org.hyperic.hq.hqapi1.types.ResourcesResponse; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * The Hyperic HQ Resource Edge API. + *

+ * This class provides access to relationships between resources in HQ. + */ +public class ResourceEdgeApi extends BaseApi { + + ResourceEdgeApi(HQConnection conn) { + super(conn); + } + + public ResourceEdgesResponse getResourceEdges(String resourceRelation, + Integer resourceId, + String prototype, + String name) + throws IOException { + + Map params = new HashMap(); + params.put("resourceRelation", new String[] { resourceRelation}); + params.put("prototype", new String[] { prototype }); + params.put("name", new String[] { name }); + if (resourceId != null) { + params.put("id", new String[] { resourceId.toString() }); + } + return doGet("resource/getResourceEdges.hqu", params, + ResourceEdgesResponse.class); + } + + public ResourcesResponse getParentResourcesByRelation(String resourceRelation, + String prototype, + String name, + boolean hasChildren) + throws IOException { + + Map params = new HashMap(); + params.put("prototype", new String[] { prototype }); + params.put("name", new String[] { name }); + params.put("resourceRelation", new String[] { resourceRelation }); + params.put("hasChildren", new String[] { Boolean.valueOf(hasChildren).toString() }); + return doGet("resource/getParentResourcesByRelation.hqu", params, + ResourcesResponse.class); + } + + public ResourcesResponse getResourcesByNoRelation(String resourceRelation, + String prototype, + String name) + throws IOException { + + Map params = new HashMap(); + params.put("prototype", new String[] { prototype }); + params.put("name", new String[] { name }); + params.put("resourceRelation", new String[] { resourceRelation }); + return doGet("resource/getResourcesByNoRelation.hqu", params, + ResourcesResponse.class); + } + + public StatusResponse syncResourceEdges(List edges) + throws IOException { + + ResourceEdgesRequest request = new ResourceEdgesRequest(); + request.getResourceEdge().addAll(edges); + return doPost("resource/syncResourceEdges.hqu", request, StatusResponse.class); + } + + public StatusResponse createResourceEdges(List edges) + throws IOException { + + ResourceEdgesRequest request = new ResourceEdgesRequest(); + request.getResourceEdge().addAll(edges); + return doPost("resource/createResourceEdges.hqu", request, StatusResponse.class); + } + + public StatusResponse deleteResourceEdges(List edges) + throws IOException { + + ResourceEdgesRequest request = new ResourceEdgesRequest(); + request.getResourceEdge().addAll(edges); + return doPost("resource/deleteResourceEdges.hqu", request, StatusResponse.class); + } + + public StatusResponse deleteResourceEdges(String resourceRelation, int id) + throws IOException { + + Map params = new HashMap(); + params.put("resourceRelation", new String[] { resourceRelation }); + params.put("id", new String[] { Integer.toString(id) }); + return doGet("resource/deleteAllResourceEdges.hqu", params, StatusResponse.class); + } +} \ No newline at end of file