OW2 Consortium elastic-grid

Compare Revisions

Ignore whitespace Rev 449 → Rev 455

/trunk/applications/rest-api/src/main/java/com/elasticgrid/rest/RestApplication.java
18,26 → 18,57
 
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 implements InitializingBean, DisposableBean {
private SpringComponent component;
public class RestApplication extends WadlApplication {
private Component 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");
60,26 → 91,8
return "Elastic Grid REST API";
}
 
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 {
@Override
protected void finalize() throws Throwable {
component.stop();
}
 
91,8 → 104,7
// do nothing -- allow everything
}
});
 
ApplicationContext ctx = new ClassPathXmlApplicationContext("/com/elasticgrid/rest/applicationContext.xml");
new RestApplication();
}
 
}
Property changes:
Deleted: 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,19 → 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 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,19 → 41,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.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,18 → 29,17
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,16 → 29,15
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,7 → 19,10
package com.elasticgrid.rest;
 
import com.elasticgrid.cluster.ClusterManager;
import com.elasticgrid.model.*;
import com.elasticgrid.model.Cluster;
import com.elasticgrid.model.ClusterProvisioning;
import com.elasticgrid.model.NodeProfile;
import com.elasticgrid.model.NodeProfileInfo;
import com.elasticgrid.model.ec2.EC2NodeType;
import com.elasticgrid.model.internal.Clusters;
import org.jibx.runtime.JiBXException;
39,7 → 42,6
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;
49,12 → 51,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,30 → 18,39
 
package com.elasticgrid.rest;
 
import com.sun.jini.start.LifeCycle;
import org.rioproject.associations.*;
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 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 org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
import com.sun.jini.start.LifeCycle;
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 */
109,42 → 118,31
}
}
 
/**
* 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);
springContext = new ClassPathXmlApplicationContext("/com/elasticgrid/rest/applicationContext.xml");
initializeClusterManager();
new RestApplication();
}
 
@Override
public void destroy(boolean force) {
if (springContext != null)
springContext.close();
super.destroy(force);
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));
}
 
/**
* An AssociationListener for Provision Monitor instances
* Get the component name to use for accessing the services configuration properties
*
* @return The component name
*/
static class ProvisionMonitorListener implements AssociationListener<ProvisionMonitor> {
public void discovered(Association association, ProvisionMonitor provisionMonitor) {
setProvisionMonitor(provisionMonitor);
}
public static String getConfigComponent() {
return configComponent;
}
 
public void changed(Association association, ProvisionMonitor provisionMonitor) {
}
 
public void broken(Association association, ProvisionMonitor provisionMonitor) {
setProvisionMonitor(null);
}
public static ClusterManager getClusterManager() {
return clusterManager;
}
 
public static ProvisionMonitor getProvisionMonitor() {
167,4 → 165,20
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,17 → 39,16
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;
61,18 → 60,19
private String clusterName;
private String dropBucket;
private Configuration config;
 
@Autowired
private S3Service s3;
 
@Autowired
private S3Service s3 = AWSUtils.getS3Service();
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,9 → 230,4
public boolean allowDelete() {
return false;
}
 
@Required
public void setDropBucket(String dropBucket) {
this.dropBucket = dropBucket;
}
}