Commit 2835447c authored by Łukasz Nowak's avatar Łukasz Nowak

Remove java (it is in rest branch).

java implementation depends on rest implementation and it is not stable enough
to be shown on master branch.
parent 3c261f9a
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
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.slapos.slap</groupId>
<artifactId>slapos.slap</artifactId>
<packaging>jar</packaging>
<version>0.1-slapproxy-SNAPSHOT</version>
<name>slapos.slap</name>
<url>http://www.slapos.org</url>
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
<repository>
<id>maven-repository.java.net</id>
<name>Java.net Maven 1 Repository (legacy)</name>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
<finalName>slapos.slap</finalName>
</build>
</project>
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
package org.slapos.slap;
import java.util.HashMap;
import java.util.Map;
import org.slapos.slap.*;
import com.sun.jersey.api.client.Client;
/**
* This class is a simple example or test for libslap-java, showing how to request instances or fetch parameters.
* @author cedricdesaintmartin
*
*/
public class Example {
public static void main(String[] args) {
// Should not be a singleton
Slap slap = new Slap();
slap.initializeConnection("http://localhost:5000");
// We should not have to require
slap.registerComputer("computer");
String software = "https://gitorious.org/slapos/slapos-software-proactive/blobs/raw/master/software.cfg";
// Installs a software in the computer
Supply supply = slap.registerSupply();
supply.supply(software, "computer");
// Asks an instance of the installed software
OpenOrder oo = slap.registerOpenOrder();
Map<String, Object> parameterDict = new HashMap<String, Object>();
parameterDict.put("credentials", "bububu");
parameterDict.put("rmURL", "bububu");
parameterDict.put("nsName", "bububu");
ComputerPartition cp = oo.request(software, "slappart0", parameterDict, null);
String helloworld = "https://gitorious.org/slapos/slapos-software-helloworld/blobs/raw/master/software.cfg";
// Installs a software in the computer
Supply supply2 = slap.registerSupply();
supply2.supply(helloworld, "computer");
OpenOrder oo2 = slap.registerOpenOrder();
ComputerPartition cp2 = oo2.request(helloworld, "slappart1", null, null);
while (true) {
try {
System.out.println((String) cp.getConnectionParameter("useless_parameter"));
} catch (Exception e) {
System.out.println(e.getMessage());
}
try {
Thread.sleep(30000);
} catch (InterruptedException e) {}
}
}
}
/******************************************************************************
*
* 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) {
// 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.exception;
/**
* public interfacees which implement INotFoundError are used to report missing
* informations on the slap server.
**/
public class NotFoundException extends Exception {
public NotFoundException(String string) {
super(string);
}
}
\ 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.exception;
/**
* public interfacees which implement IUnauthorized are used to report missing
* permissions on the slap server.
*/
public class UnauthorizedException extends Exception {
}
\ 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.interfaces;
/**
* public interfacees which implement IBuildoutController can report the buildout run
* status to the slapgrid server.
*/
public interface IBuildoutController {
/**
* Notify (to the slapgrid server) that the software instance is
* available.
*/
public void available();
/**
* Notify (to the slapgrid server) that the buildout is not
* available and under creation.
*/
public void building();
/**
* Notify (to the slapgrid server) that the buildout is not available
* and reports an error.
*
* error_log -- a text describing the error
* It can be a traceback for example.
*/
public void error(String error_log);
}
\ 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.interfaces;
import java.util.ArrayList;
/**
* Computer interface specification
*
* public interfacees which implement IComputer can fetch informations from the slapgrid
* server to know which Software Releases and Software Instances have to be
* installed.
*/
public interface IComputer {
/**
* 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();
/**
* Returns the list of configured computer partitions associated to this
* computer.
*
* Raise an INotFoundError if computer_guid doesn't exist.
*/
public ArrayList<IComputerPartition> getComputerPartitionList();
/**
* Report the computer usage to the slapgrid server.
* IComputerPartition.setUsage has to be called on each computer partition to
* public functionine each usage.
*
* computer_partition_list -- a list of computer partition for which the usage
* needs to be reported.
*/
public void reportUsage(String[] computer_partition_list);
}
\ 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.interfaces;
import java.util.Map;
/**
* Computer Partition interface specification
* public interfacees which implement IComputerPartition can propagate the computer
* partition state to the SLAPGRID server and request new computer partition
* creation.
*/
public interface IComputerPartition extends IBuildoutController {
/**
* Request software release instanciation to slapgrid server.
*
* Returns a new computer partition document, where this sofware release will
* be installed.
*
* software_release -- uri of the software release
* which has to be instanciated
*
* software_type -- type of component provided by software_release
*
* partition_reference -- local reference of the instance used by the recipe
* to identify the instances.
*
* shared -- boolean to use a shared service
*
* partition_parameter_kw -- dictionary of parameter used to fill the
* parameter dict of newly created partition.
*
* filter_kw -- dictionary of filtering parameter to select the requested
* computer partition.
*
* computer_reference - computer of the requested partition
* partition_type - virtio, slave, full, limited
* port - port provided by the requested partition
*
* Example:
* request('http://example.com/toto/titi', 'mysql_1')
*/
public IComputerPartition request(String softwareRelease, String softwareType,
String partitionReference,
boolean shared, // = false
Map<String, Object> partitionParameter, // = null
Map<String, String> filter); // = null
/**
* Notify (to the slapgrid server) that the software instance is
* available and stopped.
*/
public void stopped();
/**
* Notify (to the slapgrid server) that the software instance is
* available and started.
*/
public void started();
/**
* Returns a string representing the identifier of the computer partition
* inside the slapgrid server.
*/
public String getId();
/**
* Returns a string representing the expected state of the computer partition.
* The result can be: started, stopped, destroyed
*/
public String getState();
/**
* Returns the software release associate to the computer partition.
* Raise an INotFoundError if no software release is associated.
*/
public String getSoftwareRelease();
/**
* Returns a dictionary of instance parameters.
*
* The contained values can be used to fill the software instanciation
* profile.
*/
public Map<String, String> getInstanceParameterDict();
/**
* Set instance parameter informations on the slagrid server.
*
* partition_parameter_kw -- dictionary of parameters.
*
* This method can be used to propagate connection informations (like
* service's port).
*/
public void setInstanceParameterDict(Map<String, String> partition_parameter_kw);
/**
* Associate a usage log to the computer partition.
* This method does not report the usage to the slapgrid server. See
* IComputer.report.
*
* usage_log -- a text describing the computer partition usage.
* It can be an XML for example.
*/
public void setUsage(String usage_log);
}
/******************************************************************************
*
* 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.interfaces;
import java.util.Map;
/**
* Open Order interface specification
*
* public interfacees which implement Open Order describe which kind of software instances
* is requested by a given client.
*/
public interface IOpenOrder {
/**
* Request the instanciation of a given software release to the slapgrid
* server.
*
* Returns a new computer partition document, where this software release will
* be installed.
*
* software_release -- uri of the software release
* which has to be instanciated
*/
public IComputerPartition request(String software_release, String partition_reference,
Map<String, Object> partition_parameter_kw, String software_type);
}
\ 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.interfaces;
import org.slapos.slap.exception.NotFoundException;
/**
* Note: all strings accepted/returned by the slap library are encoded in UTF-8.
* Initialise slap connection to the slapgrid server
*
* Slapgrid server URL is public functionined during the slap library
* installation, as recipes should not use another server.
*/
public interface ISlap {
/**
* Initialize the connection parameters to the slapgrid servers.
*
* slapgrid_uri -- uri the slapgrid server connector
*
* authentification_key -- string the authentificate the agent.
*
* Example: https://slapos.server/slap_interface
*/
public void initializeConnection(String slapgridUri,
String authentificationKey);
/**
* Initialize the connection parameters to the slapgrid servers.
*
* slapgrid_uri -- uri the slapgrid server connector
*
* authentification_key -- string the authentificate the agent.
*
* Example: https://slapos.server/slap_interface
*/
public void initializeConnection(String slapgridUri);
/**
* Instanciate a computer in the slap library.
*
* computer_guid -- the identifier of the computer inside the slapgrid
* server.
*/
public IComputer registerComputer(String computerGuid);
/**
* Instanciate a computer partition in the slap library, fetching
* informations from master server.
*
* @param computerGuid
* -- the identifier of the computer inside the slapgrid server.
*
* @param partitionId
* -- the identifier of the computer partition inside the
* slapgrid server.
*
* Raise a NotFoundError if computer_guid doesn't exist.
*/
public IComputerPartition registerComputerPartition(String computerGuid,
String partitionId) throws NotFoundException;
/**
* Instanciate a software release in the slap library.
*
* @param softwareRelease
* -- uri of the software release public functioninition
* @throws Exception
*/
public ISoftwareRelease registerSoftwareRelease(String softwareReleaseUrl) throws Exception;
/**
* Instanciate an open order in the slap library.
* @return
*/
public IOpenOrder registerOpenOrder();
/**
* Instanciate a supply in the slap library.
*/
public ISupply registerSupply();
}
\ 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.interfaces;
/**
* Software release interface specification
*/
public interface ISoftwareRelease extends IBuildoutController {
/**
* Returns a string representing the uri of the software release.
*/
public String getURI();
}
\ 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.interfaces;
/**
* Supply interface specification
*
* public interfacees which implement Supply describe which kind of software releases
* a given client is ready to supply.
*/
public interface ISupply {
/**
* Tell that given client is ready to supply given sofware release
*
* software_release -- uri of the software release
* which has to be instanciated
*
* computer_guid -- the identifier of the computer inside the slapgrid
* server.
*/
public void supply(String software_release, String computer_guid);
/**
* Tell that given client is ready to supply given sofware release
*
* software_release -- uri of the software release
* which has to be instanciated
*/
public void supply(String software_release);
}
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Define the XML Schema of a transaction -->
<xs:element name="instance">
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" minOccurs="0" maxOccurs="unbounded">
<xs:complexType mixed="true">
<xs:attribute name="id" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="unique_instance_parameter_id">
<xs:selector xpath="./parameter"/>
<xs:field xpath="@id"/>
</xs:unique>
</xs:element>
</xs:schema>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment