Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » writing a cloudlet(how to subscribe)
writing a cloudlet [message #1713189] Mon, 02 November 2015 08:28 Go to next message
paul stanton is currently offline paul stantonFriend
Messages: 87
Registered: July 2009
Member
hi all,

another thing i've found difficult to trace is how to implement/extend cloudlet.

I have looked at the sourcecode of 'CommandCloudApp' and 'CloudConfigurationHandler' which are the only extensions of Cloudlet I could fine, and it isn't obvious how they subscribe to and route messages for their respective restful handlers.

Sending the app_id into the constructor, I was hoping that the 'doGet/doPut...' methods would just be called when an appropriate topic is published ie Cloudlet would know to subscribe to #/appid/[GET/PUT/EXEC...] and do the plumbing for me

however, I can't seem to get these methods to invoke. I have tried with and without '$EDC' prefix.

Are there any examples out there or can someone explain the general process of implementing a simple Cloudlet which receives calls to 'doGet' 'doPut' when appropriate messages are published?

thanks, paul.
Re: writing a cloudlet [message #1713265 is a reply to message #1713189] Mon, 02 November 2015 20:30 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hey Paul,

The CommandCloudApp is a good resource to use as an example. How are you generating the request? I refer you again to the (poorly named) documentation on Request/Response conversations [1]. Is your request including the requester.id and requester.client.id in the payload?

[1] http://eclipse.github.io/kura/ref/mqtt-namespace.html

Thanks,
--Dave
Re: writing a cloudlet [message #1713281 is a reply to message #1713265] Tue, 03 November 2015 04:33 Go to previous messageGo to next message
paul stanton is currently offline paul stantonFriend
Messages: 87
Registered: July 2009
Member
Yes, the payload includes both of these - i'm not sure what the body/metrics are supposed to include re the value being set, but the first problem is that the cloudlet 'onMessageArrived' handler is not being called. Neither is onPut.

As mentioned, I have looked into the CommandCloudApp source but cannot find where it is explicitly subscribing to anything - which is why I was assuming something higher in the API was handling subscriptions/callbacks based on the app_id supplied in the constructor and the standard sub-topics: PUT/GET/DEL etc.
Re: writing a cloudlet [message #1713284 is a reply to message #1713281] Tue, 03 November 2015 05:45 Go to previous messageGo to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

I have an example that might help you in understanding the Cloudlet scenario and its usage.

@Component(immediate = true, name = "com.amitinside.activity.log.service")
@Service(value = { IActivityLogService.class })
public class ActivityLogService extends Cloudlet implements IActivityLogService {

	/**
	 * Defines Application ID for Activity Logs
	 */
	private static final String APP_ID = "LOGS-V1";

	/**
	 * Logger.
	 */
	private static final Logger LOGGER = LoggerFactory.getLogger(ActivityLogService.class);

	/**
	 * Cloud Service Injection
	 */
	@Reference(bind = "bindCloudService", unbind = "unbindCloudService")
	private volatile CloudService m_cloudService;

	/**
	 * Constructor
	 */
	public ActivityLogService() {
		super(APP_ID);
	}

	/**
	 * Callback while this component is getting registered
	 *
	 * @param properties
	 *            the service configuration properties
	 */
	@Override
	@Activate
	protected synchronized void activate(final ComponentContext context) {
		LOGGER.info("Activating Activity Log Service....");
		super.setCloudService(this.m_cloudService);
		super.activate(context);
		LOGGER.info("Activating Activity Log Service... Done.");
	}

	/**
	 * Kura Cloud Service Binding Callback
	 */
	public synchronized void bindCloudService(final CloudService cloudService) {
		if (this.m_cloudService == null) {
			super.setCloudService(this.m_cloudService = cloudService);
		}
	}

	/**
	 * Callback while this component is getting deregistered
	 *
	 * @param properties
	 *            the service configuration properties
	 */
	@Override
	@Deactivate
	protected synchronized void deactivate(final ComponentContext context) {
		LOGGER.info("Deactivating Activity Log Service....");
		super.deactivate(context);
		LOGGER.info("Deactivating Activity Log Service... Done.");
	}

	/** {@inheritDoc} */
	@Override
	protected void doGet(final CloudletTopic reqTopic, final KuraRequestPayload reqPayload,
			final KuraResponsePayload respPayload) throws KuraException {
                //if mqtt clients need to retrieve logs
		if ("logs".equals(reqTopic.getResources()[0])) {
			respPayload.addMetric("tumlog", this.retrieveLogs(LogFileType.TUM));
			respPayload.addMetric("kuralog", this.retrieveLogs(LogFileType.KURA));
		}
		respPayload.setResponseCode(KuraResponsePayload.RESPONSE_CODE_OK);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String retrieveLogs(final LogFileType type) {
		LOGGER.debug("Retrieving logs from the Activity Logs Database...");
		//Logs retrieval custom implementation
		LOGGER.debug("Retrieving logs from the Activity Logs Database...Done");
		return "";
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void saveLog(final String log) {
		LOGGER.debug("Saving log to the Activity Logs Database...");
		//Logs storing custom implementation
		LOGGER.debug("Saving log to the Activity Logs Database...Done");
	}

	/**
	 * Kura Cloud Service Callback while deregistering
	 */
	public synchronized void unbindCloudService(final CloudService cloudService) {
		if (this.m_cloudService == cloudService) {
			super.setCloudService(this.m_cloudService = null);
		}
	}
}


If you have any question, feel free to ask.


Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Re: writing a cloudlet [message #1713307 is a reply to message #1713284] Tue, 03 November 2015 09:34 Go to previous message
paul stanton is currently offline paul stantonFriend
Messages: 87
Registered: July 2009
Member
amit that was very helpful!

My problem was that I just wasn't calling `super.activate`

All working now it seems...
Previous Topic:To Configure WEB UI of KURA
Next Topic:Kura doesn't start on IDP XT 3.0 64 bit
Goto Forum:
  


Current Time: Tue Apr 23 16:26:17 GMT 2024

Powered by FUDForum. Page generated in 0.02780 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top