pax_global_header 0000666 0000000 0000000 00000000064 11571371576 0014527 g ustar 00root root 0000000 0000000 52 comment=371513a4474b7f2e34b34ca48a02d4af7037a936
slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/ 0000775 0000000 0000000 00000000000 11571371576 0021021 5 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/.gitignore 0000664 0000000 0000000 00000000045 11571371576 0023010 0 ustar 00root root 0000000 0000000 *pyc
build
dist
slapos.core.egg-info
slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/CHANGES.txt 0000664 0000000 0000000 00000000451 11571371576 0022632 0 ustar 00root root 0000000 0000000 0.2 (2011-06-01)
================
* Include required files in distribution [Ćukasz Nowak]
0.1 (2011-05-27)
================
* Merged slapos.slap, slapos.tool.console, slapos.tool.format,
slapos.tool.grid, slapos.tool.libnetworkcache and slapos.tool.proxy into one
package: slapos.core
slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/MANIFEST.in 0000664 0000000 0000000 00000000223 11571371576 0022554 0 ustar 00root root 0000000 0000000 include CHANGES.txt
include slapos/proxy/schema.sql
recursive-include slapos/ *.in
recursive-include slapos/ *.txt
recursive-include slapos/ *.xsd
slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/README.txt 0000664 0000000 0000000 00000000055 11571371576 0022517 0 ustar 00root root 0000000 0000000 slapos.core
===========
The core of SlapOS.
slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/buildout.cfg 0000664 0000000 0000000 00000000603 11571371576 0023330 0 ustar 00root root 0000000 0000000 [buildout]
develop = .
parts =
slapos
pyflakes
find-links =
http://www.nexedi.org/static/packages/source/slapos.buildout/
versions = versions
[pyflakes]
recipe = zc.recipe.egg
scripts =
pyflakes
eggs =
pyflakes
setuptools
[slapos]
recipe = z3c.recipe.scripts
eggs =
slapos.core
ipython
ipdb
pyflakes
pep8
rstctl
[versions]
zc.buildout = 1.5.3-dev-SlapOS-001
slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/computer_definition.cfg.example 0000664 0000000 0000000 00000000357 11571371576 0027207 0 ustar 00root root 0000000 0000000 [computer]
[partition_0]
address = 200.11.11.11/255.255.255.0
user = myuser
network_interface = virtual
pathname = inpart0
[partition_1]
address = 3.3.3.3/255.255.0.0
user = anotheruser
network_interface = tpslaptap1
pathname = inpart1
slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/ 0000775 0000000 0000000 00000000000 11571371576 0021742 5 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/ 0000775 0000000 0000000 00000000000 11571371576 0022701 5 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/README.md 0000664 0000000 0000000 00000004762 11571371576 0024171 0 ustar 00root root 0000000 0000000 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) slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/pom.xml 0000664 0000000 0000000 00000003024 11571371576 0024215 0 ustar 00root root 0000000 0000000 4.0.0org.slapos.slapslapos.slapjar0.1-slapproxy-SNAPSHOTslapos.slaphttp://www.slapos.orgmaven2-repository.java.netJava.net Repository for Mavenhttp://download.java.net/maven/2/defaultmaven-repository.java.netJava.net Maven 1 Repository (legacy)http://download.java.net/maven/1legacycom.sun.jerseyjersey-client1.7com.sun.jerseyjersey-json1.7maven-compiler-plugin1.5slapos.slap
slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/ 0000775 0000000 0000000 00000000000 11571371576 0023470 5 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/main/ 0000775 0000000 0000000 00000000000 11571371576 0024414 5 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/main/java/ 0000775 0000000 0000000 00000000000 11571371576 0025335 5 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/main/java/org/ 0000775 0000000 0000000 00000000000 11571371576 0026124 5 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/main/java/org/slapos/ 0000775 0000000 0000000 00000000000 11571371576 0027425 5 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/main/java/org/slapos/slap/ 0000775 0000000 0000000 00000000000 11571371576 0030364 5 ustar 00root root 0000000 0000000 ClientWrapper.java 0000664 0000000 0000000 00000007232 11571371576 0033733 0 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/main/java/org/slapos/slap 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) 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, converts it to json, and send it to URI.
* @param uri
* @param parameterList
* @return
* @throws Exception
*/
public String post(String uri, Map 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>() {}
//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);
}
} Computer.java 0000664 0000000 0000000 00000007451 11571371576 0032755 0 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/main/java/org/slapos/slap /******************************************************************************
*
* 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 softwareReleaseList;
private ArrayList 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 getSoftwareReleaseList() {
syncComputerInformation();
return this.softwareReleaseList;
}
public ArrayList getComputerPartitionList() {
syncComputerInformation();
ArrayList partitionToModifyList = new ArrayList();
for (ComputerPartition partition : computerPartitionList) {
if (partition.need_modification) {
partitionToModifyList.add(partition);
}
}
return partitionToModifyList;
}
public void reportUsage(ArrayList 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
}
} ComputerPartition.java 0000664 0000000 0000000 00000030133 11571371576 0034640 0 ustar 00root root 0000000 0000000 slapos.core-0.2-371513a4474b7f2e34b34ca48a02d4af7037a936/java/slap/src/main/java/org/slapos/slap /******************************************************************************
*
* 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 java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.slapos.slap.exception.NotFoundException;
import org.slapos.slap.interfaces.IComputerPartition;
/*def _syncComputerPartitionInformation(func):
"""
Synchronize computer partition object with server information
"""
def decorated(self, *args, **kw):
computer = self._connection_helper.getComputerInformation(self._computer_id)
found_computer_partition = None
for computer_partition in computer._computer_partition_list:
if computer_partition.getId() == self.getId():
found_computer_partition = computer_partition
break
if found_computer_partition is None:
raise NotFoundError("No software release information for partition %s" %
self.getId())
else:
for key, value in found_computer_partition.__dict__.items():
if isinstance(value, unicode):
# convert unicode to utf-8
setattr(self, key, value.encode('utf-8'))
if isinstance(value, dict):
new_dict = {}
for ink, inv in value.iteritems():
if isinstance(inv, (list, tuple)):
new_inv = []
for elt in inv:
if isinstance(elt, (list, tuple)):
new_inv.append([x.encode('utf-8') for x in elt])
else:
new_inv.append(elt.encode('utf-8'))
new_dict[ink.encode('utf-8')] = new_inv
elif inv is None:
new_dict[ink.encode('utf-8')] = None
else:
new_dict[ink.encode('utf-8')] = inv.encode('utf-8')
setattr(self, key, new_dict)
else:
setattr(self, key, value)
return func(self, *args, **kw)
return decorated
*/
// FIXME beware! I am not respecting Java conventions, but be aware that JSON is unmarshalled to instance of this crap. If you change those attributes, please consider also changing the slapos protocol.
public class ComputerPartition extends SlapDocument implements IComputerPartition {
private String computer_id;
private String computer_partition_id; // Id is internal representation of instance in slapos
private String partition_reference; // reference is human chosen name for the instance
//TODO enum for requestedState, not string.
private String requested_state;
//TODO private, getters/setters
public Map parameter_dict;
public boolean need_modification;
public Map connection_dict;
public String software_release;
private String software_type;
private boolean shared;
private Map filter;
private ClientWrapper connection;
public ComputerPartition(String computerId, String partitionId) {
this.computer_id = computerId;
this.computer_partition_id = partitionId;
}
public ComputerPartition(ClientWrapper connection) {
this.connection = connection;
}
//FIXME @_syncComputerPartitionInformation
public ComputerPartition request(String softwareRelease, String softwareType, String partitionReference,
boolean shared, Map partitionParameter, Map filter) {
//shared=False, filter_kw=None
if (partitionParameter == null) {
partitionParameter = new HashMap();
}
if (filter == null) {
filter = new HashMap();
}
ComputerPartition cp = new ComputerPartition(computer_id, computer_partition_id);
cp.setSoftware_release(softwareRelease);
cp.setSoftware_type(softwareType);
cp.setPartition_reference(partitionReference);
cp.setShared(shared);
cp.setParameter_dict(partitionParameter);
cp.setFilter(filter);
// Sends it, reads response
return sendRequest(cp);
}
/**
* This methods is used as a helper for ComputerPartition.request and OpenOrder.request. Those 2 methods prepare the parameterList, while this one actually sends the request to server
* @param parameterList
* @return
*/
public ComputerPartition sendRequest(ComputerPartition cp) {
// Converts computer partition to Json
String parameterJson = ClientWrapper.object2Json(cp, "ComputerPartition");
// Sends it, reads response
ComputerPartition computerPartition = null;
try {
String responseJson = connection.post("/partition", parameterJson);
ObjectMapper mapper = new ObjectMapper();
//FIXME change slap protocol to receive something that looks like a ComputerPartition, so that we can unmarshal it automatically
//FIXME in the python slap library, only slap_computer_id and slap_computer_partition_id are used. What about the other parameter received?
Map softwareInstance = mapper.readValue(responseJson, Map.class);
computerPartition = new ComputerPartition(
//TODO : check encoding.
(String) softwareInstance.get("slap_computer_id"),
(String) softwareInstance.get("slap_computer_partition_id"));
computerPartition.setPartition_reference((String) softwareInstance.get("partition_reference"));
//FIXME connection_xml is deprecated, and is a string. We need to stabilize slap code in slapproxy & al.
//computerPartition.setConnection_dict((Map) softwareInstance.get("connection_xml"));
computerPartition.setSoftware_release((String) softwareInstance.get("slap_software_release_url"));
//TODO Requested State
} 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();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return computerPartition;
}
/**
* Synchronizing computer partition informations with server. Currently, it is ugly and not network efficient. PoC.
*/
private void SyncComputerPartitionInformation() {
// Fetches informations
String responseJson = connection.get("/" + this.computer_id);
ObjectMapper mapper = new ObjectMapper();
// Take our computer partition, replace this.blabla with what we find
try {
Map computer = mapper.readValue(responseJson, Map.class);
ArrayList