/****Alberto&Loredana*****/
package eu.mosaic_cloud.sla;
import eu.mosaic_cloud.cloudlets.connectors.kvstore.IKvStoreConnector;
import eu.mosaic_cloud.cloudlets.connectors.kvstore.IKvStoreConnectorFactory;
import eu.mosaic_cloud.cloudlets.connectors.kvstore.KvStoreCallbackCompletionArguments;
import eu.mosaic_cloud.cloudlets.core.CallbackArguments;
import eu.mosaic_cloud.cloudlets.core.CloudletCallbackArguments;
import eu.mosaic_cloud.cloudlets.core.CloudletCallbackCompletionArguments;
import eu.mosaic_cloud.cloudlets.core.ICallback;
import eu.mosaic_cloud.cloudlets.core.ICloudletController;
import eu.mosaic_cloud.cloudlets.tools.DefaultCloudletCallback;
import eu.mosaic_cloud.cloudlets.tools.DefaultKvStoreConnectorCallback;
import eu.mosaic_cloud.platform.core.configuration.ConfigurationIdentifier;
import eu.mosaic_cloud.platform.core.configuration.IConfiguration;
import eu.mosaic_cloud.platform.core.utils.JsonDataEncoder;
import eu.mosaic_cloud.tools.callbacks.core.CallbackCompletion;
public class CSPupload {
public static final class KeyValueCallback
extends DefaultKvStoreConnectorCallback<CSPuploadCloudletContext, String, Void>
{
@Override
public CallbackCompletion<Void> destroySucceeded (final CSPuploadCloudletContext context, final CallbackArguments arguments)
{
this.logger.info ("CSPuploadCloudlet store destroyed successfully.");
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> initializeSucceeded (final CSPuploadCloudletContext context, final CallbackArguments arguments)
{
this.logger.info ("CSPuploadCloudlet store initialized successfully.");
return ICallback.SUCCESS;
}
public CallbackCompletion<Void> setSucceeded (final CSPuploadCloudletContext context, final KvStoreCallbackCompletionArguments<String, Void> arguments)
{
this.logger.info("Set kvStar : OK");
String kv=arguments.getKey();
String vl=arguments.getValue();
this.logger.info("SetChiave: "+kv);
this.logger.info("SetValore: "+vl);
//context.kvStore.get(kv, null);
return ICallback.SUCCESS;
}
public CallbackCompletion<Void> getSucceeded (final CSPuploadCloudletContext context, final KvStoreCallbackCompletionArguments<String, Void> arguments)
{
this.logger.info("Get Succeded: OK");
String kv=arguments.getKey();
String vl=(String)arguments.getValue();
this.logger.info("GetChiave: "+kv);
this.logger.info("GetValore: "+vl);
return ICallback.SUCCESS;
}
}
public static final class KeyValueIdCallback
extends DefaultKvStoreConnectorCallback<CSPuploadCloudletContext, InfoCSPs, Void>
{
@Override
public CallbackCompletion<Void> destroySucceeded (final CSPuploadCloudletContext context, final CallbackArguments arguments)
{
this.logger.info ("CSPuploadCloudlet IDstore destroyed successfully.");
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> initializeSucceeded (final CSPuploadCloudletContext context, final CallbackArguments arguments)
{
this.logger.info ("CSPuploadCloudlet IDstore initialized successfully.");
return ICallback.SUCCESS;
}
public CallbackCompletion<Void> setSucceeded (final CSPuploadCloudletContext context, final KvStoreCallbackCompletionArguments<InfoCSPs, Void> arguments)
{
this.logger.info("Set kvID : OK");
String kv=arguments.getKey();
InfoCSPs in=(InfoCSPs)arguments.getValue();
//String vl=arguments.getValue();
this.logger.info("SetChiave: "+kv);
this.logger.info("Numero di provider: "+in.getSize());
for(int i=0;i<in.getSize();i++){
this.logger.info("Set Valore: "+in.getCSP(i));
}
//this.logger.info("SetValore: "+vl);
//context.kvStore.get(kv, null);
return ICallback.SUCCESS;
}
public CallbackCompletion<Void> getSucceeded (final CSPuploadCloudletContext context, final KvStoreCallbackCompletionArguments<InfoCSPs, Void> arguments)
{
this.logger.info("Get Succeded: OK");
//String kv=arguments.getKey();
//String vl=(String)arguments.getValue();
//this.logger.info("GetChiave: "+kv);
//this.logger.info("GetValore: "+vl);
return ICallback.SUCCESS;
}
}
public static final class LifeCycleHandler
extends DefaultCloudletCallback<CSPuploadCloudletContext>
{
@Override
public CallbackCompletion<Void> destroy (final CSPuploadCloudletContext context, final CloudletCallbackArguments<CSPuploadCloudletContext> arguments)
{
this.logger.info ("CSPuploadCloudlet destroying...");
return context.cloudlet.destroy ();
}
@Override
public CallbackCompletion<Void> destroySucceeded (final CSPuploadCloudletContext context, final CloudletCallbackCompletionArguments<CSPuploadCloudletContext> arguments)
{
this.logger.info ("CSPuploadCloudlet destroyed successfully.");
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> initialize (final CSPuploadCloudletContext context, final CloudletCallbackArguments<CSPuploadCloudletContext> arguments)
{
this.logger.info ("CSPuploadCloudlet initializing...");
context.cloudlet = arguments.getCloudlet ();
final IConfiguration configuration = context.cloudlet.getConfiguration ();
final IConfiguration kvConfiguration = configuration.spliceConfiguration (ConfigurationIdentifier.resolveAbsolute ("star"));
context.kvStore = context.cloudlet.getConnectorFactory (IKvStoreConnectorFactory.class).create (kvConfiguration, String.class, JsonDataEncoder.create(String.class), new KeyValueCallback (), context);
final IConfiguration kvIdConfiguration = configuration.spliceConfiguration (ConfigurationIdentifier.resolveAbsolute ("idstore"));
context.kvStoreId = context.cloudlet.getConnectorFactory (IKvStoreConnectorFactory.class).create (kvIdConfiguration, InfoCSPs.class, JsonDataEncoder.create(InfoCSPs.class), new KeyValueIdCallback (), context);
return CallbackCompletion.createAndChained (context.kvStoreId.initialize (),context.kvStore.initialize ());
}
@Override
public CallbackCompletion<Void> initializeSucceeded (final CSPuploadCloudletContext context, final CloudletCallbackCompletionArguments<CSPuploadCloudletContext> arguments)
{
context.doc=new QPT();
context.doc.setName("CSP1");
context.doc.setSecLa("AND{ SA-01.1:4" +
"SA-01.Q1:1" +
"} SA-01" +
"AND{ SA-02.1:4" +
"SA-02.2:4" +
"SA-02.3:4" +
"SA-02.4:4" +
"SA-02.5:4" +
"SA-02.6:4" +
"SA-02.7:4" +
"} SA-02" +
"AND{ SA-03.1:4" +
"} SA-03" +
"AND{" +
"SA-04.1:4" +
"SA-04.2:4" +
"} SA-04" +
"AND{ SA-05.1:4" +
"} SA-05" +
"AND{ SA-06.1:4" +
"} SA-06" +
"AND{ SA-07.1:4" +
"} SA-07" +
"AND{ SA-09.1:4" +
"SA-09.2:4" +
"SA-09.3:4" +
"SA-09.4:4" +
"} SA-09" +
"AND{ SA-12.1:4" +
"} SA-12" +
"AND{ SA-13.1:4" +
"} SA-13" +
"AND{ SA-14.1:4" +
"SA-14.2:4" +
"SA-14.3:4" +
"} SA-14" +
"AND{ SA-01" +
"SA-02" +
"SA-03" +
"SA-04" +
"SA-05" +
"SA-06" +
"SA-07" +
"SA-09" +
"SA-12" +
"SA-13" +
"SA-14" +
"} SA");
context.doc2=new QPT();
context.doc2.setName("CSP2-Mimecast");
context.doc2.setSecLa("AND{ SA-01.1:4" +
"SA-01.Q1:4" +
"} SA-01" +
"AND{ SA-02.1:4" +
"SA-02.2:4" +
"SA-02.3:1" +
"SA-02.4:1" +
"SA-02.5:1" +
"SA-02.6:1" +
"SA-02.7:4" +
"} SA-02" +
"AND{ SA-03.1:4" +
"} SA-03" +
"AND{ SA-04.1:1" +
"SA-04.2:4" +
"} SA-04" +
"AND{ SA-05.1:4" +
"} SA-05" +
"AND{ SA-06.1:1" +
"} SA-06" +
"AND{ SA-07.1:4" +
"} SA-07" +
"AND{ SA-09.1:4" +
"SA-09.2:4" +
"SA-09.3:4" +
"SA-09.4:4" +
"} SA-09" +
"AND{ SA-12.1:4" +
"} SA-12" +
"AND{ SA-13.1:1" +
"} SA-13" +
"AND{ SA-14.1:4" +
"SA-14.2:4" +
"SA-14.3:4" +
"} SA-14" +
"AND{ SA-01" +
"SA-02" +
"SA-03" +
"SA-04" +
"SA-05" +
"SA-06" +
"SA-07" +
"SA-09" +
"SA-12" +
"SA-13" +
"SA-14" +
"} SA");
context.doc3=new QPT();
context.doc3.setName("CSP3-Solutionar");
context.doc3.setSecLa("AND{ SA-01.1:4" +
"SA-01.Q1:3" +
"} SA-01" +
"AND{ SA-02.1:4" +
"SA-02.2:4" +
"SA-02.3:1" +
"SA-02.4:1" +
"SA-02.5:4" +
"SA-02.6:4" +
"SA-02.7:4" +
"} SA-02" +
"AND{ SA-03.1:4" +
"} SA-03" +
"AND{ SA-04.1:4" +
"SA-04.2:4" +
"} SA-04" +
"AND{ SA-05.1:4" +
"} SA-05" +
"AND{ SA-06.1:4" +
"} SA-06" +
"AND{ SA-07.1:1" +
"} SA-07" +
"AND{ SA-09.1:4" +
"SA-09.2:4" +
"SA-09.3:4" +
"SA-09.4:4" +
"} SA-09" +
"AND{ SA-12.1:4" +
"} SA-12" +
"AND{ SA-13.1:4" +
"} SA-13" +
"AND{ SA-14.1:4" +
"SA-14.2:4" +
"SA-14.3:4" +
"} SA-14" +
"AND{ SA-01" +
"SA-02" +
"SA-03" +
"SA-04" +
"SA-05" +
"SA-06" +
"SA-07" +
"SA-09" +
"SA-12" +
"SA-13" +
"SA-14" +
"} SA");
this.logger.info ("CSPuploadCloudlet initialized successfully.");
context.kvStore.set(context.doc.getName(),context.doc.getSecLa(), null);
context.kvStore.set(context.doc2.getName(),context.doc2.getSecLa(), null);
context.kvStore.set(context.doc3.getName(),context.doc3.getSecLa(), null);
context.ids.setCSP(context.doc.getName());
context.ids.setCSP(context.doc2.getName());
context.ids.setCSP(context.doc3.getName());
context.kvStoreId.set(context.id, context.ids, null);
return ICallback.SUCCESS;
}
}
public static final class CSPuploadCloudletContext
{
ICloudletController<CSPuploadCloudletContext> cloudlet;
IKvStoreConnector<String, Void> kvStore;
IKvStoreConnector<InfoCSPs, Void> kvStoreId;
QPT doc,doc2,doc3;
InfoCSPs ids=new InfoCSPs();
String id="Id";
}
}