OW2 Consortium elastic-grid

Rev

Rev 121 | Rev 127 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 jeje 1
/**
2
 * Copyright (C) 2007-2008 Elastic Grid, LLC.
3
 *
4
 * This file is part of Elastic Grid.
5
 *
6
 * Elastic Grid is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, either version 3 of the
9
 * License, or any later version.
10
 *
11
 * Elastic Grid is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with Elastic Grid.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
 
20
package com.elasticgrid.rest;
21
 
22
import org.restlet.resource.Resource;
23
import org.restlet.resource.Variant;
24
import org.restlet.resource.Representation;
25
import org.restlet.resource.ResourceException;
26
import org.restlet.data.MediaType;
27
import org.restlet.data.Response;
28
import org.restlet.data.Request;
125 jeje 29
import org.restlet.data.Method;
119 jeje 30
import org.restlet.Context;
31
import org.restlet.ext.jibx.JibxRepresentation;
121 jeje 32
import org.restlet.ext.wadl.WadlResource;
125 jeje 33
import org.restlet.ext.wadl.MethodInfo;
34
import org.restlet.ext.wadl.DocumentationInfo;
35
import org.restlet.ext.wadl.ResourceInfo;
119 jeje 36
import com.elasticgrid.model.internal.Clusters;
37
import com.elasticgrid.model.ec2.impl.EC2ClusterImpl;
38
import com.elasticgrid.cluster.ClusterManager;
39
 
121 jeje 40
public class ClustersResource extends WadlResource {
119 jeje 41
    private ClusterManager clusterManager;
42
 
43
    public ClustersResource(Context context, Request request, Response response) {
44
        super(context, request, response);
125 jeje 45
        // Allow modifications of this resource via POST requests
46
        setModifiable(true);
47
        // Declare the kind of representations supported by this resource
119 jeje 48
        getVariants().add(new Variant(MediaType.APPLICATION_XML));
49
    }
50
 
125 jeje 51
    /**
52
     * Handle GET requests: describe all clusters.
53
     */
119 jeje 54
    @Override
55
    public Representation represent(Variant variant) throws ResourceException {
56
        Clusters clusters = new Clusters();
57
        clusters.addCluster(new EC2ClusterImpl().name("cluster1"));
58
        clusters.addCluster(new EC2ClusterImpl().name("cluster2"));
59
        clusters.addCluster(new EC2ClusterImpl().name("cluster3"));
60
        return new JibxRepresentation<Clusters>(MediaType.APPLICATION_XML, clusters, "ElasticGridREST");
61
//        List<Cluster> clusters = null;
62
//        try {
120 jeje 63
//            clusters = clusterManager.findClusters();
64
//            return new JibxRepresentation<Clusters>(MediaType.APPLICATION_XML, new Clusters(clusters), "ElasticGridREST");
119 jeje 65
//        } catch (Exception e) {
120 jeje 66
//            throw new ResourceException(Status.SERVER_ERROR_SERVICE_UNAVAILABLE, e);
119 jeje 67
//        }
68
    }
69
 
125 jeje 70
    /**
71
     * Handle POST requests: start a new cluster.
72
     * @param entity
73
     * @throws ResourceException
74
     */
75
    @Override
76
    public void acceptRepresentation(Representation entity) throws ResourceException {
77
        super.acceptRepresentation(entity);
78
    }
79
 
80
    @Override
81
    protected void describeGet(MethodInfo info) {
82
        super.describeGet(info);
83
        info.setDocumentation("Describe all Elastic Grid clusters.");
84
    }
85
 
86
    @Override
87
    protected void describePost(MethodInfo info) {
88
        super.describePost(info);
89
        info.setDocumentation("Start a new cluster.");
90
    }
119 jeje 91
}