package eu.mosaic_cloud.sla;
import eu.mosaic_cloud.cloudlets.connectors.queue.amqp.AmqpQueueConsumeCallbackArguments;
import eu.mosaic_cloud.cloudlets.connectors.queue.amqp.IAmqpQueueConsumerConnector;
import eu.mosaic_cloud.cloudlets.connectors.queue.amqp.IAmqpQueueConsumerConnectorFactory;
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.GenericCallbackCompletionArguments;
import eu.mosaic_cloud.cloudlets.core.ICallback;
import eu.mosaic_cloud.cloudlets.core.ICloudletController;
import eu.mosaic_cloud.cloudlets.tools.DefaultAmqpQueueConsumerConnectorCallback;
import eu.mosaic_cloud.cloudlets.tools.DefaultCloudletCallback;
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 TestResultCloudlet {
public static final class AmqpResultCallback
extends DefaultAmqpQueueConsumerConnectorCallback<TestResultCloudletContext, QPT[], Void>
{
@Override
public CallbackCompletion<Void> acknowledgeSucceeded (final TestResultCloudletContext context, final GenericCallbackCompletionArguments<Void> arguments)
{
//context.cloudlet.destroy ();
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> consume (final TestResultCloudletContext context, final AmqpQueueConsumeCallbackArguments<QPT[]> arguments)
{
//prendo dalla coda Cagw il QPT user
this.logger.info("Entered consume");
context.list=arguments.getMessage();
this.logger.info ("TestResultCloudlet received message :"+context.list[0].getName()+" SecLA: "+context.list[0].getSecLa());
this.logger.info ("TestResultCloudlet received message :"+context.list[1].getName()+" SecLA: "+context.list[1].getSecLa());
this.logger.info ("TestResultCloudlet received message :"+context.list[2].getName()+" SecLA: "+context.list[2].getSecLa());
context.testresult.acknowledge (arguments.getToken ());
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> destroySucceeded (final TestResultCloudletContext context, final CallbackArguments arguments)
{
this.logger.info ("TestResultCloudlet consumer destroyed successfully.");
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> initializeSucceeded (final TestResultCloudletContext context, final CallbackArguments arguments)
{
this.logger.info ("TestResultCloudlet consumer initialized successfully.");
return ICallback.SUCCESS;
}
}
public static final class LifeCycleHandler
extends DefaultCloudletCallback<TestResultCloudletContext>
{
@Override
public CallbackCompletion<Void> destroy (final TestResultCloudletContext context, final CloudletCallbackArguments<TestResultCloudletContext> arguments)
{
this.logger.info ("TestResultCloudlet destroying...");
return context.testresult.destroy ();
}
@Override
public CallbackCompletion<Void> destroySucceeded (final TestResultCloudletContext context, final CloudletCallbackCompletionArguments<TestResultCloudletContext> arguments)
{
this.logger.info ("TestResultCloudlet destroyed successfully.");
return ICallback.SUCCESS;
}
@Override
public CallbackCompletion<Void> initialize (final TestResultCloudletContext context, final CloudletCallbackArguments<TestResultCloudletContext> arguments)
{
this.logger.info ("TestResultCloudlet initializing...");
context.cloudlet = arguments.getCloudlet ();
final IConfiguration configuration = context.cloudlet.getConfiguration ();
final IConfiguration queueResultConfiguration = configuration.spliceConfiguration (ConfigurationIdentifier.resolveAbsolute ("queue.testresult"));
context.testresult = context.cloudlet.getConnectorFactory (IAmqpQueueConsumerConnectorFactory.class).create (queueResultConfiguration, QPT[].class, JsonDataEncoder.create(QPT[].class), new AmqpResultCallback (), context);
return CallbackCompletion.createAndChained (context.testresult.initialize ());
}
@Override
public CallbackCompletion<Void> initializeSucceeded (final TestResultCloudletContext context, final CloudletCallbackCompletionArguments<TestResultCloudletContext> arguments)
{
this.logger.info ("TestResultCloudlet initialized successfully.");
return ICallback.SUCCESS;
}
}
public static final class TestResultCloudletContext
{
ICloudletController<TestResultCloudletContext> cloudlet;
IAmqpQueueConsumerConnector<QPT[], Void> testresult;
QPT list[]=new QPT[20];
}
}