OW2 Consortium elastic-grid

Compare Revisions

Ignore whitespace Rev 455 → Rev 449

/trunk/applications/rest-api/src/test/java/com/elasticgrid/rest/RestTest.java
New file
0,0 → 1,171
/**
* Elastic Grid
* Copyright (C) 2008-2009 Elastic Grid, LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
 
package com.elasticgrid.rest;
 
import com.elasticgrid.cluster.ClusterManager;
import com.elasticgrid.model.ClusterException;
import com.elasticgrid.model.NodeProfileInfo;
import com.elasticgrid.model.NodeProfile;
import com.elasticgrid.model.ec2.EC2NodeType;
import com.elasticgrid.model.internal.Clusters;
import org.jibx.runtime.JiBXException;
import org.restlet.Client;
import org.restlet.data.Protocol;
import org.restlet.data.Reference;
import org.restlet.data.Response;
import org.restlet.data.Status;
import org.restlet.ext.jibx.JibxRepresentation;
import org.restlet.resource.Representation;
import org.restlet.resource.ResourceException;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.Arrays;
 
@ContextConfiguration(locations = {"/com/elasticgrid/rest/applicationContext.xml" })
public class RestTest extends AbstractTestNGSpringContextTests {
private Client client;
private static final String ROOT = "http://localhost:8182/eg";
 
@Test
public void testListOfClusters() throws IOException, ResourceException, JiBXException {
Representation representation = get(client, new Reference(ROOT));
Clusters clusters = new JibxRepresentation<Clusters>(representation, Clusters.class, "ElasticGridREST").getObject();
assert clusters != null;
assert clusters.getClusters().size() == 2;
}
 
/*
@Test
public void testProvisioningOfClusters() throws IOException, ResourceException, JiBXException {
// create a new cluster
ClusterProvisioning provisioningRequest = new ClusterProvisioning();
provisioningRequest.setClusterName("my-cluster");
provisioningRequest.setNumberOfMonitors(2);
provisioningRequest.setNumberOfAgents(3);
Representation request = new JibxRepresentation<ClusterProvisioning>(MediaType.APPLICATION_XML,
provisioningRequest, "ElasticGridREST");
post(client, new Reference(ROOT), request);
Representation representation = get(client, new Reference(ROOT));
Clusters clusters = new JibxRepresentation<Clusters>(representation, Clusters.class, "ElasticGridREST").getObject();
assert clusters != null;
assert clusters.getClusters().size() == 3;
 
// update the cluster
provisioningRequest.setNumberOfMonitors(12);
provisioningRequest.setNumberOfAgents(100);
request = new JibxRepresentation<ClusterProvisioning>(MediaType.APPLICATION_XML,
provisioningRequest, "ElasticGridREST");
post(client, new Reference(ROOT + "/my-cluster"), request);
representation = get(client, new Reference(ROOT + "/my-cluster"));
Cluster cluster = new JibxRepresentation<Cluster>(representation, EC2ClusterImpl.class, "ElasticGridREST").getObject();
assert cluster != null;
assert "my-cluster".equals(cluster.getName());
assert cluster.getNodes().size() == 112;
 
// delete the cluster
delete(client, new Reference(ROOT + "/my-cluster"));
representation = get(client, new Reference(ROOT));
clusters = new JibxRepresentation<Clusters>(representation, Clusters.class, "ElasticGridREST").getObject();
assert clusters != null;
assert clusters.getClusters().size() == 2;
}
 
@Test
public void testDescriptionOfCluster() throws IOException, ResourceException, JiBXException {
Representation representation = get(client, new Reference(ROOT + "/fake1"));
Cluster cluster = new JibxRepresentation<Cluster>(representation, EC2ClusterImpl.class, "ElasticGridREST").getObject();
assert cluster != null;
assert "fake1".equals(cluster.getName());
assert cluster.getNodes().size() == 1;
}
*/
 
@BeforeTest
public void setupRestClient() {
// Define our Restlet HTTP client.
client = new Client(Protocol.HTTP);
}
 
@BeforeMethod
public void setupDummyClusters() throws TimeoutException, ExecutionException, RemoteException, ClusterException, InterruptedException {
ClusterManager clusterManager = (ClusterManager) applicationContext.getBean("clusterManager");
NodeProfileInfo monitorAndAgent = new NodeProfileInfo(NodeProfile.MONITOR_AND_AGENT, EC2NodeType.SMALL, 1);
clusterManager.startCluster("fake1", Arrays.asList(monitorAndAgent));
clusterManager.startCluster("fake2", Arrays.asList(monitorAndAgent));
}
 
/**
* Send a GET request.
*
* @param client client Restlet.
* @param reference the resource's URI.
* @return the representation at the requested URL
* @throws IOException if there is a networking issue
* @throws ResourceException if the resource is invalid
*/
private Representation get(Client client, Reference reference) throws ResourceException, IOException {
Response response = client.get(reference);
if (response.getStatus().isSuccess()) {
if (response.isEntityAvailable()) {
return response.getEntity();
}
}
response.getEntity().write(System.err);
throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY);
}
 
/**
* Send a POST request.
*
* @param client client Restlet.
* @param reference the resource's URI.
* @param representation the representation to send as input
* @throws IOException if there is a networking issue
* @throws ResourceException if the resource is invalid
*/
private void post(Client client, Reference reference, Representation representation) throws ResourceException, IOException {
Response response = client.post(reference, representation);
if (!response.getStatus().isSuccess()) {
throw new ResourceException(response.getStatus());
}
}
 
/**
* Send a DELETE request.
*
* @param client client Restlet.
* @param reference the resource's URI.
* @throws IOException if there is a networking issue
* @throws ResourceException if the resource is invalid
*/
private void delete(Client client, Reference reference) throws ResourceException, IOException {
Response response = client.delete(reference);
if (!response.getStatus().isSuccess()) {
throw new ResourceException(response.getStatus());
}
}
 
}
/trunk/applications/rest-api/src/test/resources/com/elasticgrid/cluster/applicationContext.xml
New file
0,0 → 1,28
<?xml version="1.0" encoding="UTF-8"?>
<!--
 
Elastic Grid
Copyright (C) 2008-2009 Elastic Grid, LLC.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
-->
 
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 
<bean id="clusterManager" class="com.elasticgrid.cluster.ClusterManagerMock"/>
 
</beans>
/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/RestApplication.java
18,57 → 18,26
 
package com.elasticgrid.rest;
 
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.Router;
import org.restlet.data.Protocol;
import org.restlet.data.Reference;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.ext.spring.SpringComponent;
import org.restlet.ext.wadl.ApplicationInfo;
import org.restlet.ext.wadl.GrammarsInfo;
import org.restlet.ext.wadl.IncludeInfo;
import org.restlet.ext.wadl.WadlApplication;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.rmi.RMISecurityManager;
import java.security.Permission;
 
public class RestApplication extends WadlApplication {
private Component component;
public class RestApplication extends WadlApplication implements InitializingBean, DisposableBean {
private SpringComponent component;
 
public RestApplication() {
try {
// Create a new Component.
component = new Component();
 
// Add a new HTTP server listening on port 8182.
component.getServers().add(Protocol.HTTP, 8182);
 
// Attach the sample application.
component.getDefaultHost().attach(this);
 
// Start the component.
component.start();
} catch (Exception e) {
// Something is wrong.
e.printStackTrace();
}
setName("Elastic Grid REST API");
setAuthor("Elastic Grid, LLC.");
}
 
@Override
public Restlet createRoot() {
Router router = new Router(getContext());
router.attach("/eg", ClustersResource.class);
router.attach("/eg/{clusterName}", ClusterResource.class);
router.attach("/eg/{clusterName}/applications", ApplicationsResource.class);
router.attach("/eg/{clusterName}/applications/{applicationName}", ApplicationResource.class);
router.attach("/eg/{clusterName}/applications/{applicationName}/services", ServicesResource.class);
router.attach("/eg/{clusterName}/applications/{applicationName}/services/{serviceName}", ServiceResource.class);
return router;
}
 
@Override
public ApplicationInfo getApplicationInfo(Request request, Response response) {
ApplicationInfo appInfo = super.getApplicationInfo(request, response);
appInfo.getNamespaces().put("urn:elastic-grid:eg", "eg");
91,8 → 60,26
return "Elastic Grid REST API";
}
 
@Override
protected void finalize() throws Throwable {
public void afterPropertiesSet() throws Exception {
try {
// Create a new Component.
component = new SpringComponent();
 
// Add a new HTTP server listening on port 8182.
component.getServers().add(Protocol.HTTP, 8182);
 
// Attach the sample application.
component.getDefaultHost().attach(this);
 
// Start the component.
component.start();
} catch (Exception e) {
// Something is wrong.
e.printStackTrace();
}
}
 
public void destroy() throws Exception {
component.stop();
}
 
104,7 → 91,8
// do nothing -- allow everything
}
});
new RestApplication();
 
ApplicationContext ctx = new ClassPathXmlApplicationContext("/com/elasticgrid/rest/applicationContext.xml");
}
 
}
Property changes:
Added: svn:executable
+ *
/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/ServiceResource.java
1,18 → 1,18
/**
* Elastic Grid
* Copyright (C) 2008-2009 Elastic Grid, LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* Elastic Grid
* Copyright (C) 2008-2009 Elastic Grid, LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
 
29,18 → 29,19
import org.restlet.resource.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Arrays;
 
public class ServiceResource extends WadlResource {
private String clusterName;
private String applicationName;
private String serviceName;
@Autowired
private ClusterManager clusterManager;
 
@Override
public void init(Context context, Request request, Response response) {
super.init(context, request, response);
clusterManager = RestJSB.getClusterManager();
// Allow modifications of this resource via POST requests
setModifiable(false);
setAutoDescribed(true);
/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/ClusterResource.java
21,8 → 21,8
import com.elasticgrid.cluster.ClusterManager;
import com.elasticgrid.model.Cluster;
import com.elasticgrid.model.ClusterProvisioning;
import com.elasticgrid.model.NodeProfileInfo;
import com.elasticgrid.model.NodeProfile;
import com.elasticgrid.model.NodeProfileInfo;
import com.elasticgrid.model.ec2.EC2NodeType;
import org.jibx.runtime.JiBXException;
import org.restlet.Context;
41,18 → 41,19
import org.restlet.resource.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeoutException;
 
public class ClusterResource extends WadlResource {
private String clusterName;
@Autowired
private ClusterManager clusterManager;
 
@Override
public void init(Context context, Request request, Response response) {
super.init(context, request, response);
clusterManager = RestJSB.getClusterManager();
// Allow modifications of this resource via POST requests
setModifiable(true);
setAutoDescribed(true);
/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/ApplicationResource.java
1,18 → 1,18
/**
* Elastic Grid
* Copyright (C) 2008-2009 Elastic Grid, LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* Elastic Grid
* Copyright (C) 2008-2009 Elastic Grid, LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
 
29,17 → 29,18
import org.restlet.resource.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Arrays;
 
public class ApplicationResource extends WadlResource {
private String clusterName;
private String applicationName;
@Autowired
private ClusterManager clusterManager;
 
@Override
public void init(Context context, Request request, Response response) {
super.init(context, request, response);
clusterManager = RestJSB.getClusterManager();
// Allow modifications of this resource via POST requests
setModifiable(true);
setAutoDescribed(true);
/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/ServicesResource.java
1,18 → 1,18
/**
* Elastic Grid
* Copyright (C) 2008-2009 Elastic Grid, LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* Elastic Grid
* Copyright (C) 2008-2009 Elastic Grid, LLC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
 
29,15 → 29,16
import org.restlet.resource.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Arrays;
 
public class ServicesResource extends WadlResource {
@Autowired
private ClusterManager clusterManager;
 
@Override
public void init(Context context, Request request, Response response) {
super.init(context, request, response);
clusterManager = RestJSB.getClusterManager();
// Allow modifications of this resource via POST requests
setModifiable(false);
// Declare the kind of representations supported by this resource
/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/ClustersResource.java
19,10 → 19,7
package com.elasticgrid.rest;
 
import com.elasticgrid.cluster.ClusterManager;
import com.elasticgrid.model.Cluster;
import com.elasticgrid.model.ClusterProvisioning;
import com.elasticgrid.model.NodeProfile;
import com.elasticgrid.model.NodeProfileInfo;
import com.elasticgrid.model.*;
import com.elasticgrid.model.ec2.EC2NodeType;
import com.elasticgrid.model.internal.Clusters;
import org.jibx.runtime.JiBXException;
42,6 → 39,7
import org.restlet.resource.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
51,12 → 49,12
* TODO: update the REST API documentation for this resource.
*/
public class ClustersResource extends WadlResource {
@Autowired
private ClusterManager<Cluster> clusterManager;
 
@Override
public void init(Context context, Request request, Response response) {
super.init(context, request, response);
clusterManager = RestJSB.getClusterManager();
// Allow modifications of this resource via POST requests
setModifiable(true);
// Declare the kind of representations supported by this resource
/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/RestJSB.java
18,39 → 18,30
 
package com.elasticgrid.rest;
 
import com.elasticgrid.cluster.CloudFederationClusterManager;
import com.elasticgrid.cluster.ClusterManager;
import com.elasticgrid.cluster.spi.CloudPlatformManager;
import com.elasticgrid.model.ec2.EC2Cluster;
import com.elasticgrid.model.lan.LANCluster;
import com.elasticgrid.platforms.ec2.EC2CloudPlatformManagerFactory;
import com.elasticgrid.platforms.lan.LANCloudPlatformManagerFactory;
import org.rioproject.associations.Association;
import org.rioproject.associations.AssociationDescriptor;
import org.rioproject.associations.AssociationListener;
import org.rioproject.associations.AssociationMgmt;
import org.rioproject.associations.AssociationType;
import com.sun.jini.start.LifeCycle;
import org.rioproject.associations.*;
import org.rioproject.core.OperationalStringManager;
import org.rioproject.core.jsb.ServiceBeanContext;
import org.rioproject.jsb.ServiceBeanActivation;
import org.rioproject.jsb.ServiceBeanAdapter;
import org.rioproject.monitor.DeployAdmin;
import org.rioproject.monitor.ProvisionMonitor;
import com.sun.jini.start.LifeCycle;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
 
/**
* JSB exposing the underlying REST API.
*/
public class RestJSB extends ServiceBeanAdapter {
private static CloudFederationClusterManager clusterManager;
private static ProvisionMonitor provisionMonitor;
private ConfigurableApplicationContext springContext;
/** Component name we use to find items in the Configuration */
static final String RIO_CONFIG_COMPONENT = "com.elasticgrid";
/** Component name we use to find items in the Configuration */
118,31 → 109,42
}
}
 
/**
* Get the component name to use for accessing the services configuration properties
*
* @return The component name
*/
public static String getConfigComponent() {
return configComponent;
}
 
@Override
public void initialize(ServiceBeanContext context) throws Exception {
super.initialize(context);
initializeClusterManager();
new RestApplication();
springContext = new ClassPathXmlApplicationContext("/com/elasticgrid/rest/applicationContext.xml");
}
 
public static void initializeClusterManager() throws IOException {
clusterManager = new CloudFederationClusterManager();
CloudPlatformManager<LANCluster> lanCloud = new LANCloudPlatformManagerFactory().getInstance();
CloudPlatformManager<EC2Cluster> ec2Cloud = new EC2CloudPlatformManagerFactory().getInstance();
clusterManager.setClouds(Arrays.asList(lanCloud, ec2Cloud));
@Override
public void destroy(boolean force) {
if (springContext != null)
springContext.close();
super.destroy(force);
}
 
/**
* Get the component name to use for accessing the services configuration properties
*
* @return The component name
* An AssociationListener for Provision Monitor instances
*/
public static String getConfigComponent() {
return configComponent;
}
static class ProvisionMonitorListener implements AssociationListener<ProvisionMonitor> {
public void discovered(Association association, ProvisionMonitor provisionMonitor) {
setProvisionMonitor(provisionMonitor);
}
 
public static ClusterManager getClusterManager() {
return clusterManager;
public void changed(Association association, ProvisionMonitor provisionMonitor) {
}
 
public void broken(Association association, ProvisionMonitor provisionMonitor) {
setProvisionMonitor(null);
}
}
 
public static ProvisionMonitor getProvisionMonitor() {
165,20 → 167,4
public static void setProvisionMonitor(ProvisionMonitor provisionMonitor) {
RestJSB.provisionMonitor = provisionMonitor;
}
 
/**
* An AssociationListener for Provision Monitor instances
*/
static class ProvisionMonitorListener implements AssociationListener<ProvisionMonitor> {
public void discovered(Association association, ProvisionMonitor provisionMonitor) {
setProvisionMonitor(provisionMonitor);
}
 
public void changed(Association association, ProvisionMonitor provisionMonitor) {
}
 
public void broken(Association association, ProvisionMonitor provisionMonitor) {
setProvisionMonitor(null);
}
}
}
/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/ApplicationsResource.java
20,8 → 20,8
 
import com.elasticgrid.cluster.ClusterManager;
import com.elasticgrid.model.Cluster;
import com.elasticgrid.model.internal.Clusters;
import com.elasticgrid.model.internal.Applications;
import com.elasticgrid.utils.amazon.AWSUtils;
import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
39,16 → 39,17
import org.restlet.data.Status;
import org.restlet.ext.fileupload.RestletFileUpload;
import org.restlet.ext.freemarker.TemplateRepresentation;
import org.restlet.ext.jibx.JibxRepresentation;
import org.restlet.ext.wadl.DocumentationInfo;
import org.restlet.ext.wadl.MethodInfo;
import org.restlet.ext.wadl.RepresentationInfo;
import org.restlet.ext.wadl.WadlResource;
import org.restlet.ext.jibx.JibxRepresentation;
import org.restlet.resource.Representation;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
60,19 → 61,18
private String clusterName;
private String dropBucket;
private Configuration config;
private S3Service s3 = AWSUtils.getS3Service();
 
@Autowired
private S3Service s3;
 
@Autowired
private ClusterManager clusterManager;
 
private final Logger logger = Logger.getLogger(getClass().getName());
 
@Override
public void init(Context context, Request request, Response response) {
super.init(context, request, response);
clusterManager = RestJSB.getClusterManager();
try {
dropBucket = AWSUtils.getDropBucket();
} catch (IOException e) {
throw new IllegalStateException("Can't retrieve drop bucket", e);
}
// Allow modifications of this resource via POST requests
setModifiable(true);
// Declare the kind of representations supported by this resource
230,4 → 230,9
public boolean allowDelete() {
return false;
}
 
@Required
public void setDropBucket(String dropBucket) {
this.dropBucket = dropBucket;
}
}
/trunk/applications/rest-api/src/main/resources/com/elasticgrid/rest/applicationContext.xml
New file
0,0 → 1,116
<?xml version="1.0" encoding="UTF-8"?>
<!--
 
Elastic Grid
Copyright (C) 2008-2009 Elastic Grid, LLC.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
-->
 
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
<import resource="classpath:/com/elasticgrid/cluster/applicationContext.xml"/>
 
<bean id="application" class="com.elasticgrid.rest.RestApplication">
<property name="name" value="Elastic Grid REST API"/>
<property name="author" value="Elastic Grid, LLC."/>
<property name="root" ref="root"/>
</bean>
 
<bean id="root" class="org.restlet.ext.spring.SpringRouter">
<property name="attachments">
<map>
<entry key="/eg" value-ref="clustersFinder"/>
<entry key="/eg/{clusterName}" value-ref="clusterFinder"/>
<entry key="/eg/{clusterName}/applications" value-ref="applicationsFinder"/>
<entry key="/eg/{clusterName}/applications/{applicationName}" value-ref="applicationFinder"/>
<entry key="/eg/{clusterName}/applications/{applicationName}/services" value-ref="servicesFinder"/>
<entry key="/eg/{clusterName}/applications/{applicationName}/services/{serviceName}" value-ref="serviceFinder"/>
</map>
</property>
</bean>
 
<bean id="clustersFinder" class="org.restlet.ext.spring.SpringFinder">
<lookup-method name="createResource" bean="clustersResource"/>
<property name="targetClass" value="com.elasticgrid.rest.ClustersResource"/>
</bean>
<bean id="clusterFinder" class="org.restlet.ext.spring.SpringFinder">
<lookup-method name="createResource" bean="clusterResource"/>
<property name="targetClass" value="com.elasticgrid.rest.ClusterResource"/>
</bean>
<bean id="applicationsFinder" class="org.restlet.ext.spring.SpringFinder">
<lookup-method name="createResource" bean="applicationsResource"/>
<property name="targetClass" value="com.elasticgrid.rest.ApplicationsResource"/>
</bean>
<bean id="applicationFinder" class="org.restlet.ext.spring.SpringFinder">
<lookup-method name="createResource" bean="applicationResource"/>
<property name="targetClass" value="com.elasticgrid.rest.ApplicationResource"/>
</bean>
<bean id="servicesFinder" class="org.restlet.ext.spring.SpringFinder">
<lookup-method name="createResource" bean="servicesResource"/>
<property name="targetClass" value="com.elasticgrid.rest.ServicesResource"/>
</bean>
<bean id="serviceFinder" class="org.restlet.ext.spring.SpringFinder">
<lookup-method name="createResource" bean="serviceResource"/>
<property name="targetClass" value="com.elasticgrid.rest.ServiceResource"/>
</bean>
 
<bean id="clustersResource" class="com.elasticgrid.rest.ClustersResource" scope="prototype"/>
<bean id="clusterResource" class="com.elasticgrid.rest.ClusterResource" scope="prototype"/>
<bean id="applicationsResource" class="com.elasticgrid.rest.ApplicationsResource" scope="prototype">
<property name="dropBucket" value="${eg.s3.dropBucket}"/>
</bean>
<bean id="applicationResource" class="com.elasticgrid.rest.ApplicationResource" scope="prototype"/>
<bean id="servicesResource" class="com.elasticgrid.rest.ServicesResource" scope="prototype"/>
<bean id="serviceResource" class="com.elasticgrid.rest.ServiceResource" scope="prototype"/>
 
<bean id="s3" class="org.jets3t.service.impl.rest.httpclient.RestS3Service">
<constructor-arg>
<bean class="org.jets3t.service.security.AWSCredentials">
<constructor-arg index="0" value="${aws.accessId}"/>
<constructor-arg index="1" value="${aws.secretKey}"/>
</bean>
</constructor-arg>
</bean>
 
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:${EG_HOME}/config/eg.properties</value>
<value>file:${user.home}/.eg/eg.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
 
<!--
<bean id="freemarkerConfig" class="freemarker.template.Configuration">
<property name="outputEncoding" value="utf-8"/>
<property name="defaultEncoding" value="utf-8"/>
<property name="objectWrapper"><bean class="freemarker.ext.beans.BeansWrapper"/></property>
<property name="templateLoader"><bean class="freemarker.cache.ClassTemplateLoader"/></property>
</bean>
-->
 
<!--<bean id="freemarkerConfig" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">-->
<!--<property name="templateLoaderPath" value="/com/elasticgrid/rest"/>-->
<!--</bean>-->
 
</beans>
/trunk/applications/rest-api/pom.xml
55,6 → 55,33
</dependency>
<dependency>
<groupId>org.restlet</groupId>
<artifactId>org.restlet.ext.spring</artifactId>
<version>${restlet-release-version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.restlet</groupId>
<artifactId>org.restlet</artifactId>
<version>${restlet-release-version}</version>
</dependency>
121,6 → 148,16
<artifactId>jsk-lib</artifactId>
</dependency>
 
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
 
<!-- JiBX dependencies -->
<dependency>
<groupId>org.jibx</groupId>
156,10 → 193,6
<version>2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</dependency>
 
</dependencies>
 
Property changes:
Added: svn:executable
+ *