Commit b376d945 by Łukasz Nowak

Merge branch 'master' into external_buildout

2 parents a548c253 fc89018d
Showing 1000 changed files with 3387 additions and 1316 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

*pyc
build
dist
slapos.core.egg-info
*swp
/.installed.cfg
/bin/
/build/
/develop-eggs/
/dist/
/eggs/
/parts/
/slapos.core.egg-info/
0.2 (unreleased)
0.3 (unreleased)
================
* Do not use buildout internally, but rather call bootstrap command of any
provided buildout binary. [Łukasz Nowak]
0.2 (2011-06-01)
================
* Include required files in distribution [Łukasz Nowak]
0.1 (2011-05-27)
================
......
include CHANGES.txt
include slapos/format/slapos.xsd
include slapos/slap/slap_recipe_mysqldatabase.py.txt
recursive-include slapos/grid/templates *.in
include slapos/proxy/schema.sql
recursive-include slapos/ *.in
recursive-include slapos/ *.txt
recursive-include slapos/ *.xsd
......@@ -27,6 +27,7 @@ eggs =
pyflakes
pep8
rstctl
interpreter = python
[versions]
zc.buildout = 1.5.3-dev-SlapOS-001
this is libslap for Java.
More informations at http://www.slapos.org.
Dependencies :
=============
In order to use this library, please also install the following libraries :
jackson-core-asl
jackson-jaxrs
jackson-mapper-asl
jersey-client
jersey-core
You can find those libraries in this archive :
http://download.java.net/maven/2/com/sun/jersey/jersey-archive/1.6/jersey-archive-1.6.zip
Future releases of libslap-java may be provided with Maven pom.
How to use it :
This library should be used in conjunction with the "rest-json" branch of
libslap-python
(https://gitorious.org/slapos/slapos-libslap-python/commits/rest-json) and with
the "rest" branch of slapproxy
(https://gitorious.org/slapos/slapos-tool-proxy/commits/rest).
When using slapproxy, a special Buildout profile should be used :
[buildout]
extends =
https://gitorious.org/slapos/slapos/blobs/raw/master/bootstrap/software.cfg
extensions +=
mr.developer
auto-checkout = *
parts +=
pyflakes
[sources]
# mr.developer sources definition
slapos.slap = git http://git.gitorious.org/slapos/slapos-libslap-python.git branch=rest-json
slapos.tool.proxy = git git@gitorious.org:slapos/slapos-tool-proxy.git branch=rest
[pyflakes]
recipe = zc.recipe.egg
scripts =
pyflakes
eggs =
pyflakes
setuptools
entry-points = pyflakes=pkg_resources:run_script
arguments = 'pyflakes', 'pyflakes'
[slapos]
interpreter = python
eggs +=
# develop helper eggs
ipython
ipdb
pyflakes
pep8
rstctl
This profile will install the needed special branches of slapproxy and
libslap-python.
Known bugs :
=============
* Ugly, first implementation of libslap-java from python
* We should not define a computer when using slap for requesting instances, but
only to install softwares.
* Implement Destroy for ComputerPartition
* Currently, two separate notions have been interchanged. computer_partition_id
represents the internal name of the computer partition from the point of view
of slapgrid. partition_reference is the human name set by the person requesting
an instance. A bug is preventing us to separate those notions, either in the
libslap-java or in the slapproxy implementation.
Changelog :
=============
2011/05/20
===
Initial release
(Cedric de Saint Martin)
2011/05/24
===
Slap is no longer a singleton, several instances can be used at the same time with several masters.
(Cedric de Saint Martin)
\ No newline at end of file
package org.slapos.slap;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
/**
* Simple Jersey Client wrapper, including url of the slapos master.
*/
class ClientWrapper {
private Client client;
private final String masterUri;
public ClientWrapper(String masterUri) {
//TODO check uri validity (http and https)
//TODO check presence of end /
this.masterUri = masterUri;
ClientConfig config = new DefaultClientConfig();
config.getClasses().add(JacksonJsonProvider.class);
client = Client.create(config);
}
/**
* Creates a WebResource with master url + given uri.
* @param uri
*/
public WebResource resource(String uri) {
return client.resource(masterUri + uri);
}
public static String object2Json(Object parameterList, String type) {
String parameterListJson = null;
StringWriter sw = new StringWriter();
//TODO correct encoding handling, maybe do not use Writer. see javadoc for JsonEncoding
ObjectMapper mapper = new ObjectMapper();
try {
if (type.equalsIgnoreCase("ComputerPartition")) {
mapper.writeValue(sw, (ComputerPartition) parameterList);
} else {
mapper.writeValue(sw, (Map<String, Object>) parameterList);
}
parameterListJson = sw.toString();
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return parameterListJson;
}
public String get(String uri) {
WebResource webResource = resource(uri);
String response = webResource.accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
//TODO check that exception is thrown when !200
return response;
}
/**
* Takes a Map<String, Object>, converts it to json, and send it to URI.
* @param uri
* @param parameterList
* @return
* @throws Exception
*/
public String post(String uri, Map<String, Object> parameterList) throws Exception {
// Converts it to JSON
// TODO better automatic marshalling with jackson.
String parameterListJson = ClientWrapper.object2Json(parameterList, "map");
return post(uri, parameterListJson);
}
/**
* Makes a POST request to the specified URI with the corresponding string as parameter to send
* @param uri
* @param JsonObject
* @return
* @throws Exception
*/
// TODO content type?
public String post(String uri, String JsonObject) throws Exception {
WebResource webResource = resource(uri);
// FIXME there must exist a way to send a generic object as parameter and have it converted automatically to json.
ClientResponse response = webResource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, JsonObject); //new GenericType<List<StatusBean>>() {}
//TODO automatic unmarshal
if (response.getStatus() == 200) {
return response.getEntity(String.class);
}
//TODO correct exception
throw new Exception("Server responded with wrong code : " + response.getStatus() + " when requesting " + uri);
}
}
\ No newline at end of file
/******************************************************************************
*
* Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
*
* WARNING: This program as such is intended to be used by professional
* programmers who take the whole responsibility of assessing all potential
* consequences resulting from its eventual inadequacies and bugs
* End users who are looking for a ready-to-use solution with commercial
* guarantees and support are strongly adviced to contract a Free Software
* Service Company
*
* This program is Free Software; you can redistribute it and/or
* modify it under the terms of the GNU 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 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.slapos.slap;
import java.util.ArrayList;
import org.slapos.slap.interfaces.IComputer;
import org.slapos.slap.interfaces.IComputerPartition;
public class Computer extends SlapDocument implements IComputer {
private String computerId;
private ArrayList<String> softwareReleaseList;
private ArrayList<ComputerPartition> computerPartitionList;
private ClientWrapper connection;
public Computer(ClientWrapper connection, String computerId) {
this.computerId = computerId;
this.connection = connection;
}
/**
* Synchronize computer object with server information
*/
private void syncComputerInformation() {
/* def _syncComputerInformation(func):
def decorated(self, *args, **kw):
computer = self._connection_helper.getComputerInformation(self._computer_id)
for key, value in computer.__dict__.items():
if isinstance(value, unicode):
# convert unicode to utf-8
setattr(self, key, value.encode('utf-8'))
else:
setattr(self, key, value)
return func(self, *args, **kw)
return decorated */
}
/**
* Returns the list of software release which has to be supplied by the
* computer.
* Raise an INotFoundError if computer_guid doesn't exist.
*/
public ArrayList<String> getSoftwareReleaseList() {
syncComputerInformation();
return this.softwareReleaseList;
}
public ArrayList<IComputerPartition> getComputerPartitionList() {
syncComputerInformation();
ArrayList<IComputerPartition> partitionToModifyList = new ArrayList<IComputerPartition>();
for (ComputerPartition partition : computerPartitionList) {
if (partition.need_modification) {
partitionToModifyList.add(partition);
}
}
return partitionToModifyList;
}
public void reportUsage(ArrayList<ComputerPartition> computer_partition_list) {
//FIXME implement this method
/* if computer_partition_list == []:
return;
computer = Computer(self._computer_id);
computer.computer_partition_usage_list = computer_partition_list;
marshalled_slap_usage = xml_marshaller.dumps(computer);
self._connection_helper.POST('/useComputer', {
'computer_id': self._computer_id,
'use_string': marshalled_slap_usage});
*/
}
public void updateConfiguration(String xml) {/*
self.connectionHelper.POST(
"/loadComputerConfigurationFromXML", { "xml" : xml });
return this.connectionHelper.response.read();*/
}
@Override
public void reportUsage(String[] computer_partition_list) {
// FIXME Not implemented
}
}
\ No newline at end of file
/******************************************************************************
*
* Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
*
* WARNING: This program as such is intended to be used by professional
* programmers who take the whole responsibility of assessing all potential
* consequences resulting from its eventual inadequacies and bugs
* End users who are looking for a ready-to-use solution with commercial
* guarantees and support are strongly adviced to contract a Free Software
* Service Company
*
* This program is Free Software; you can redistribute it and/or
* modify it under the terms of the GNU 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 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.slapos.slap;
import java.util.HashMap;
import java.util.Map;
import org.slapos.slap.interfaces.IOpenOrder;
public class OpenOrder extends SlapDocument implements IOpenOrder {
private ClientWrapper connection;
public OpenOrder(ClientWrapper connection) {
this.connection = connection;
}
//FIXME Java conventions
public ComputerPartition request(String softwareRelease, String partition_reference,
Map<String, Object> partition_parameter_kw, String software_type) {
if (partition_parameter_kw == null) {
partition_parameter_kw = new HashMap<String, Object>();
}
ComputerPartition cp = new ComputerPartition(connection);
cp.setSoftware_release(softwareRelease);
cp.setPartition_reference(partition_reference);
cp.setParameter_dict(partition_parameter_kw);
if (software_type != null) {
cp.setSoftware_type(software_type);
}
// Sends it, reads response
return cp.sendRequest(cp);
}
}
\ No newline at end of file
/******************************************************************************
*
* Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
*
* WARNING: This program as such is intended to be used by professional
* programmers who take the whole responsibility of assessing all potential
* consequences resulting from its eventual inadequacies and bugs
* End users who are looking for a ready-to-use solution with commercial
* guarantees and support are strongly adviced to contract a Free Software
* Service Company
*
* This program is Free Software; you can redistribute it and/or
* modify it under the terms of the GNU 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 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.slapos.slap;
import java.io.IOException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.slapos.slap.interfaces.ISlap;
/*
Simple, easy to (un)marshall classes for slap client/server communication
*/
//TODO : https connection
//TODO : correct encoding?
class SlapDocument {}
class ResourceNotReady extends Exception {
/**
*
*/
private static final long serialVersionUID = -6398370634661469874L;}
class ServerError extends Exception {
/**
*
*/
private static final long serialVersionUID = 8414085299597106973L;}
/*
class ConnectionHelper:
error_message_connect_fail = "Couldn't connect to the server. Please double \
check given master-url argument, and make sure that IPv6 is enabled on \
your machine and that the server is available. The original error was:"
def getComputerInformation(self, computer_id):
self.GET('/getComputerInformation?computer_id=%s' % computer_id)
return xml_marshaller.loads(self.response.read())
*/
public class Slap implements ISlap {
private String computerGuid;
private ClientWrapper slaposMasterRestClient;
public void initializeConnection(String slaposMasterUri) {
if (slaposMasterRestClient != null) {
System.out.println("Warning : Slap has already been initialized. Reinitializing..."); // TODO logger
}
this.slaposMasterRestClient = new ClientWrapper(slaposMasterUri);
this.computerGuid = null;
}
@Override
public void initializeConnection(String slapgridUri,
String authentificationKey) {
// TODO Auto-generated method stub
}
@Override
public Computer registerComputer(String computerGuid) {
this.computerGuid = computerGuid;
return new Computer(getConnectionWrapper(), computerGuid);
}
/*
* Registers connected representation of software release and
* returns SoftwareRelease class object(non-Javadoc)
* @see org.slapos.slap.interfaces.ISlap#registerSoftwareRelease(java.lang.String)
*/
@Override
public SoftwareRelease registerSoftwareRelease(String softwareReleaseUrl) throws Exception {
//TODO Correct exception
if (computerGuid == null) {
throw new Exception("Computer has not been registered. Please use registerComputer before.");
}
return new SoftwareRelease(softwareReleaseUrl, computerGuid);
}
public ComputerPartition registerComputerPartition(String computerGuid, String partitionId) {
String jsonobj = slaposMasterRestClient.get("/" + computerGuid + "/partition/" + partitionId);
ObjectMapper mapper = new ObjectMapper();
ComputerPartition computerPartition = null;
try {
computerPartition = mapper.readValue(jsonobj, ComputerPartition.class);
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return computerPartition;
}
@Override
public OpenOrder registerOpenOrder() {
return new OpenOrder(getConnectionWrapper());
}
@Override
public Supply registerSupply() {
return new Supply(getConnectionWrapper());
}
public ClientWrapper getConnectionWrapper() {
return slaposMasterRestClient;
}
}
/******************************************************************************
*
* Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
*
* WARNING: This program as such is intended to be used by professional
* programmers who take the whole responsibility of assessing all potential
* consequences resulting from its eventual inadequacies and bugs
* End users who are looking for a ready-to-use solution with commercial
* guarantees and support are strongly adviced to contract a Free Software
* Service Company
*
* This program is Free Software; you can redistribute it and/or
* modify it under the terms of the GNU 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 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.slapos.slap;
import org.slapos.slap.interfaces.ISoftwareRelease;
/**
* Contains Software Release information
**/
public class SoftwareRelease extends SlapDocument implements ISoftwareRelease {
//FIXME change and use this class when manipulating softwarereleases. Currently only String are used.
private String softwareReleaseUri;
private String computerGuid;
public SoftwareRelease(String softwareReleaseUri, String computerGuid) {
this.softwareReleaseUri = softwareReleaseUri;
this.computerGuid = computerGuid;
}
public String getURI() {
return softwareReleaseUri;
}
@Override
public void available() {
// TODO Auto-generated method stub
}
@Override
public void building() {
// TODO Auto-generated method stub
}
@Override
public void error(String error_log) {
// TODO Auto-generated method stub
}
}
\ No newline at end of file
/******************************************************************************
*
* Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
*
* WARNING: This program as such is intended to be used by professional
* programmers who take the whole responsibility of assessing all potential
* consequences resulting from its eventual inadequacies and bugs
* End users who are looking for a ready-to-use solution with commercial
* guarantees and support are strongly adviced to contract a Free Software
* Service Company
*
* This program is Free Software; you can redistribute it and/or
* modify it under the terms of the GNU 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 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.slapos.slap;
import java.util.HashMap;
import java.util.Map;
import org.slapos.slap.interfaces.ISupply;
public class Supply extends SlapDocument implements ISupply {
private ClientWrapper connection;
public Supply(ClientWrapper connection) {
this.connection = connection;
}
public void supply(String softwareRelease, String computerGuid) {
Map<String, Object> request = new HashMap<String, Object>();
request.put("url", softwareRelease);
try {
connection.post("/" + computerGuid + "/software", request);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void supply(String software_release) {