Skip to content

Commit

Permalink
[HQ-1665] Add ResourceEdgeApi
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen committed May 26, 2009
1 parent e810905 commit 87a58c0
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/org/hyperic/hq/hqapi1/HQApi.java
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
}
131 changes: 131 additions & 0 deletions 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.
* <br><br>
* 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<String, String[]> params = new HashMap<String, String[]>();
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<String, String[]> params = new HashMap<String, String[]>();
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<String, String[]> params = new HashMap<String, String[]>();
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<ResourceEdge> edges)
throws IOException {

ResourceEdgesRequest request = new ResourceEdgesRequest();
request.getResourceEdge().addAll(edges);
return doPost("resource/syncResourceEdges.hqu", request, StatusResponse.class);
}

public StatusResponse createResourceEdges(List<ResourceEdge> edges)
throws IOException {

ResourceEdgesRequest request = new ResourceEdgesRequest();
request.getResourceEdge().addAll(edges);
return doPost("resource/createResourceEdges.hqu", request, StatusResponse.class);
}

public StatusResponse deleteResourceEdges(List<ResourceEdge> 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<String,String[]> params = new HashMap<String, String[]>();
params.put("resourceRelation", new String[] { resourceRelation });
params.put("id", new String[] { Integer.toString(id) });
return doGet("resource/deleteAllResourceEdges.hqu", params, StatusResponse.class);
}
}

0 comments on commit 87a58c0

Please sign in to comment.