Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • lennart.thiesen/de.ugoe.cs.rwm.mocci
  • rwm/de.ugoe.cs.rwm.mocci
2 results
Show changes
Showing
with 1877 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>de.ugoe.cs.rwm.mocci.connector</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
connection.project.dir=../de.ugoe.cs.rwm.mocci.connector.dummy
eclipse.preferences.version=1
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: de.ugoe.cs.rwm.mocci.connector
Bundle-SymbolicName: de.ugoe.cs.rwm.mocci.connector;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: OCCIware
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Require-Bundle: org.slf4j.api,
org.eclipse.cmf.occi.core,
de.ugoe.cs.rwm.mocci.model
Export-Package: de.ugoe.cs.rwm.mocci.connector
# Monitoring Connector
Each element in the monitoring extension has a single file in the connector implementing how to react on different REST requests addressing the corresponding OCCI element.
As the elements of the monitoring extension mainly inherit from elements of the enhanced platform extension provided by [MoDMaCAO](https://github.com/occiware/MoDMaCAO), the implementation of the lifecycle actions is quite similar. To handle the management of each individual component of a sensor, configuration management scripts have to be attached to them. Thus, in comparison to the [dummy connector](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/tree/master/de.ugoe.cs.rwm.mocci.connector.dummy), this connector allows for an actual deployment and management of sensors in a cloud environment. The skeleton for the connector of the OCCI monitoring extension is generated using [OCCI-Studio](https://github.com/occiware/OCCI-Studio).
## Attaching Configuration Management Scripts
To attach a configuration management script to a component, a user mixin serving as tag has to be created.
Moreover, the component managed over the defined script has to have this mixin attached.
Finally, the script itself is located on the MartServer, typically in a folder called roles, and has the same name
as the mixin tag.
The following figure gives an example of such an attachment.
Here, the blue element is the User Mixin which is attached to the DataGatherer which is managed over lifecycle
actions as described in the configuration management script called glances, located in the roles folder of the MartServer.
![Attachment](./example.jpg "Attachment")
*Note:* Currently, MoDMaCAO only provides a connector for [ansible](https://docs.ansible.com/).
dependencies {
//Nexus
compile group: 'org.eclipse.ocl', name: 'pivot', version: '1.3.0'
//occiware
compile group: 'org.eclipse.cmf.occi', name: 'core', version: '1.0.0'
compile group: 'org.modmacao.occi', name: 'platform', version: '1.0.0'
compile group: 'org.modmacao', name: 'cm', version: '1.0.0'
compile group: 'org.modmacao', name: 'core', version: '1.0.0'
compile group: 'org.modmacao.core', name: 'connector', version: '1.0.0'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
//maven
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore', version: '2.15.0'
compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.ecore.xmi', version: '2.15.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
sourceSets {
main {
java {
srcDir 'src-gen'
}
//output.classesDir = "$workDir/client/program"
}
}
processResources {
from(".") {
include("plugin.xml")
include("mocci.properties")
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://nexus.informatik.uni-goettingen.de/content/repositories/rwm/") {
authentication(userName: System.getenv('NEXUSUSER'), password: System.getenv('NEXUSPASSWORD'))
}
if (System.getenv('VERSION') != null) {
pom.version = System.getenv('VERSION')
println "Version is set to: " + System.getenv('VERSION')
}
pom.version = "SNAPSHOT"
pom.artifactId = "connector"
pom.groupId = "de.ugoe.cs.rwm.mocci"
}
}
}
# Copyright (c) 2016-2017 Inria
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# - Philippe Merle <philippe.merle@inria.fr>
# - Faiez Zalila <faiez.zalila@inria.fr>
#
source.. = src-gen/
output.. = bin/
bin.includes = META-INF/, plugin.xml, .
de.ugoe.cs.rwm.mocci.connector/example.jpg

349 KiB

default_endpoint=172.19.0.1:8080
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!--
Copyright (c) 2016-2017 Inria
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
- Philippe Merle <philippe.merle@inria.fr>
- Faiez Zalila <faiez.zalila@inria.fr>
-->
<plugin>
<!-- Register the factory of this connector. -->
<extension point="org.eclipse.emf.ecore.factory_override">
<factory
uri="http://schemas.ugoe.cs.rwm/monitoring/ecore"
class="de.ugoe.cs.rwm.mocci.connector.ConnectorFactory"/>
</extension>
</plugin>
package de.ugoe.cs.rwm.mocci.connector;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.core.MixinBase;
import org.eclipse.cmf.occi.infrastructure.Compute;
import org.modmacao.cm.ConfigurationManagementTool;
import org.modmacao.cm.ansible.AnsibleCMTool;
import org.modmacao.occi.platform.Component;
import org.modmacao.occi.platform.Status;
import modmacao.Executiondependency;
import modmacao.Installationdependency;
public class ComponentManager {
private ConfigurationManagementTool cmtool = new AnsibleCMTool();
private Component comp;
public ComponentManager(Component comp) {
this.comp = comp;
}
public void undeploy() {
switch (comp.getOcciComponentState().getValue()) {
case Status.ACTIVE_VALUE:
comp.stop();
cmtool.undeploy(comp);
comp.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.INACTIVE_VALUE:
cmtool.undeploy(comp);
comp.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.DEPLOYED_VALUE:
cmtool.undeploy(comp);
comp.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.ERROR_VALUE:
cmtool.undeploy(comp);
comp.setOcciComponentState(Status.UNDEPLOYED);
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_deploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
public void deploy() {
int status = -1;
// Component State Machine.
switch (comp.getOcciComponentState().getValue()) {
case Status.UNDEPLOYED_VALUE:
for (Component component : getInstallDependendComps()) {
component.deploy();
}
status = cmtool.deploy(comp);
if (status == 0 && assertCompsStatusEquals(getInstallDependendComps(), Status.DEPLOYED)) {
comp.setOcciComponentState(Status.DEPLOYED);
} else {
comp.setOcciComponentState(Status.ERROR);
}
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
public void configure() {
int status = -1;
// Component State Machine.
switch (comp.getOcciComponentState().getValue()) {
case Status.DEPLOYED_VALUE:
for (Component component : getInstallDependendComps()) {
component.configure();
}
status = cmtool.configure(comp);
if (status == 0 && assertCompsStatusEquals(getInstallDependendComps(), Status.INACTIVE)) {
comp.setOcciComponentState(Status.INACTIVE);
} else {
comp.setOcciComponentState(Status.ERROR);
}
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
public void start() {
int status = -1;
// Component State Machine.
switch (comp.getOcciComponentState().getValue()) {
case Status.INACTIVE_VALUE:
for (Component component : getExecutionDependendComps()) {
component.start();
}
status = cmtool.start(comp);
if (status == 0 && assertCompsStatusEquals(getExecutionDependendComps(), Status.ACTIVE)) {
comp.setOcciComponentState(Status.ACTIVE);
} else {
comp.setOcciComponentState(Status.ERROR);
}
break;
case Status.UNDEPLOYED_VALUE:
for (Component component : getInstallDependendComps()) {
component.deploy();
}
comp.deploy();
for (Component component : getInstallDependendComps()) {
component.configure();
}
comp.configure();
for (Component component : getExecutionDependendComps()) {
component.start();
}
status = cmtool.start(comp);
if (status == 0 && assertCompsStatusEquals(getExecutionDependendComps(), Status.ACTIVE)) {
comp.setOcciComponentState(Status.ACTIVE);
} else {
comp.setOcciComponentState(Status.ERROR);
}
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
public void stop() {
// Component State Machine.
switch (comp.getOcciComponentState().getValue()) {
case Status.ACTIVE_VALUE:
cmtool.stop(comp);
comp.setOcciComponentState(Status.INACTIVE);
break;
default:
break;
}
}
// End of user code
private List<Component> getInstallDependendComps() {
LinkedList<Component> dependendComponents = new LinkedList<Component>();
for (Link link : comp.getLinks()) {
for (MixinBase mixin : link.getParts()) {
if (mixin instanceof Installationdependency) {
dependendComponents.add((Component) link.getTarget());
break;
}
}
}
return dependendComponents;
}
private List<Component> getExecutionDependendComps() {
LinkedList<Component> dependendComponents = new LinkedList<Component>();
for (Link link : comp.getLinks()) {
for (MixinBase mixin : link.getParts()) {
if (mixin instanceof Executiondependency) {
dependendComponents.add((Component) link.getTarget());
break;
}
}
}
return dependendComponents;
}
private boolean assertCompsStatusEquals(List<Component> components, Status status) {
for (Component component : components) {
if (component.getOcciComponentState().getValue() != status.getValue()) {
return false;
}
}
return true;
}
public static boolean isConnectedToCompute(Component comp) {
for (Link link : comp.getLinks()) {
if (link.getTarget() != null) {
if (link.getTarget() instanceof Compute) {
return true;
}
}
}
return false;
}
}
\ No newline at end of file
/**
* Copyright (c) 2016-2017 Inria
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Jan 02 16:14:48 CET 2019 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
/**
* Connector EFactory for the OCCI extension: - name: monitoring - scheme:
* http://schemas.ugoe.cs.rwm/monitoring#
*/
public class ConnectorFactory extends monitoring.impl.MonitoringFactoryImpl {
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: sensor - title: Sensor
* Component
*/
@Override
public monitoring.Sensor createSensor() {
return new SensorConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: datagatherer - title:
* DataGatherer Resource
*/
@Override
public monitoring.Datagatherer createDatagatherer() {
return new DatagathererConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: processor - title: Processor
* Resource
*/
@Override
public monitoring.Dataprocessor createDataprocessor() {
return new DataprocessorConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: publisher - title: Publisher
* Resource
*/
@Override
public monitoring.Resultprovider createResultprovider() {
return new ResultproviderConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: monitoringproperty - title:
* MonitoringProperty Component
*/
@Override
public monitoring.Monitorableproperty createMonitorableproperty() {
return new MonitorablepropertyConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: martpublisher - title:
* MartPublisher Mixin
*/
@Override
public monitoring.Occiresultprovider createOcciresultprovider() {
return new OcciresultproviderConnector();
}
}
/**
* Copyright (c) 2016-2017 Inria
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Dec 19 11:10:50 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: datagatherer - title:
* DataGatherer Resource
*/
public class DatagathererConnector extends monitoring.impl.DatagathererImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(DatagathererConnector.class);
private ComponentManager compMan;
// Start of user code Datagathererconnector_constructor
/**
* Constructs a datagatherer connector.
*/
DatagathererConnector() {
LOGGER.debug("Constructor called on " + this);
this.compMan = new ComponentManager(this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code DatagathererocciCreate
/**
* Called when this Datagatherer instance is completely created.
*/
@Override
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Datagatherer_occiRetrieve_method
/**
* Called when this Datagatherer instance must be retrieved.
*/
@Override
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Datagatherer_occiUpdate_method
/**
* Called when this Datagatherer instance is completely updated.
*/
@Override
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code DatagathererocciDelete_method
/**
* Called when this Datagatherer instance will be deleted.
*/
@Override
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
if (ComponentManager.isConnectedToCompute(this)) {
this.stop();
this.undeploy();
}
}
// End of user code
//
// Datagatherer actions.
//
// Start of user code Datagatherer_Kind_deploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
public void deploy() {
LOGGER.debug("Action deploy() called on " + this);
compMan.deploy();
// TODO: Implement how to deploy this datagatherer.
}
// End of user code
// Start of user code Datagatherer_Kind_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@Override
public void stop() {
LOGGER.debug("Action stop() called on " + this);
compMan.stop();
// TODO: Implement how to stop this datagatherer.
}
// End of user code
// Start of user code Datagatherer_Kind_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void start() {
LOGGER.debug("Action start() called on " + this);
compMan.start();
// TODO: Implement how to start this datagatherer.
}
// End of user code
// Start of user code Datagatherer_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void configure() {
LOGGER.debug("Action configure() called on " + this);
compMan.configure();
// TODO: Implement how to configure this datagatherer.
}
// End of user code
// Start of user code Datagatherer_Kind_undeploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@Override
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
compMan.undeploy();
// TODO: Implement how to undeploy this datagatherer.
}
// End of user code
}
/**
* Copyright (c) 2016-2017 Inria
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Dec 19 11:10:50 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: processor - title: Processor
* Resource
*/
public class DataprocessorConnector extends monitoring.impl.DataprocessorImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(DataprocessorConnector.class);
private ComponentManager compMan;
// Start of user code Processorconnector_constructor
/**
* Constructs a processor connector.
*/
DataprocessorConnector() {
LOGGER.debug("Constructor called on " + this);
this.compMan = new ComponentManager(this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code ProcessorocciCreate
/**
* Called when this Processor instance is completely created.
*/
@Override
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Processor_occiRetrieve_method
/**
* Called when this Processor instance must be retrieved.
*/
@Override
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Processor_occiUpdate_method
/**
* Called when this Processor instance is completely updated.
*/
@Override
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code ProcessorocciDelete_method
/**
* Called when this Processor instance will be deleted.
*/
@Override
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
if (ComponentManager.isConnectedToCompute(this)) {
this.stop();
this.undeploy();
}
}
// End of user code
//
// Processor actions.
//
// Start of user code Processor_Kind_deploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
public void deploy() {
LOGGER.debug("Action deploy() called on " + this);
compMan.deploy();
// TODO: Implement how to deploy this processor.
}
// End of user code
// Start of user code Processor_Kind_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@Override
public void stop() {
LOGGER.debug("Action stop() called on " + this);
compMan.stop();
// TODO: Implement how to stop this processor.
}
// End of user code
// Start of user code Processor_Kind_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void start() {
LOGGER.debug("Action start() called on " + this);
compMan.start();
// TODO: Implement how to start this processor.
}
// End of user code
// Start of user code Processor_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void configure() {
LOGGER.debug("Action configure() called on " + this);
compMan.configure();
// TODO: Implement how to configure this processor.
}
// End of user code
// Start of user code Processor_Kind_undeploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@Override
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
compMan.undeploy();
// TODO: Implement how to undeploy this processor.
}
// End of user code
}
/**
* Copyright (c) 2016-2017 Inria
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Jan 02 16:14:48 CET 2019 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: monitoringproperty - title:
* MonitoringProperty Component
*/
public class MonitorablepropertyConnector extends monitoring.impl.MonitorablepropertyImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(MonitorablepropertyConnector.class);
// Start of user code Monitoringpropertyconnector_constructor
/**
* Constructs a monitoringproperty connector.
*/
MonitorablepropertyConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code MonitoringpropertyocciCreate
/**
* Called when this Monitoringproperty instance is completely created.
*/
@Override
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Monitoringproperty_occiRetrieve_method
/**
* Called when this Monitoringproperty instance must be retrieved.
*/
@Override
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Monitoringproperty_occiUpdate_method
/**
* Called when this Monitoringproperty instance is completely updated.
*/
@Override
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code MonitoringpropertyocciDelete_method
/**
* Called when this Monitoringproperty instance will be deleted.
*/
@Override
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
//
// Monitoringproperty actions.
//
}
/**
* Copyright (c) 2016-2017 Inria
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Jan 02 16:14:48 CET 2019 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: martpublisher - title:
* MartPublisher Mixin
*/
public class OcciresultproviderConnector extends monitoring.impl.OcciresultproviderImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(OcciresultproviderConnector.class);
// Start of user code Martpublisherconnector_constructor
/**
* Constructs a martpublisher connector.
*/
OcciresultproviderConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
}
/**
* Copyright (c) 2016-2017 Inria
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Dec 19 11:10:50 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import org.eclipse.cmf.occi.core.*;
import org.eclipse.cmf.occi.core.impl.OCCIFactoryImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.ugoe.cs.rwm.mocci.connector.util.PropertiesHelper;
import monitoring.Monitorableproperty;
import monitoring.Occiresultprovider;
import monitoring.Sensor;
/**
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: publisher - title: Publisher
* Resource
*/
public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl {
/**
* Initialize the logger.
*/
private OCCIFactoryImpl factory = new OCCIFactoryImpl();
private static Logger LOGGER = LoggerFactory.getLogger(ResultproviderConnector.class);
private ComponentManager compMan;
private Sensor sensor;
private Monitorableproperty monProp;
private Resource monObject;
private List<AttributeState> workaround = new LinkedList<AttributeState>();
// Start of user code Publisherconnector_constructor
/**
* Constructs a publisher connector.
*/
ResultproviderConnector() {
LOGGER.debug("Constructor called on " + this);
this.compMan = new ComponentManager(this);
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code PublisherocciCreate
/**
* Called when this Publisher instance is completely created.
*/
@Override
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// check for default provider endpoint
if (rspIsDefined() == false) {
MixinBase mixB = getMartMixin();
Occiresultprovider orp = (Occiresultprovider) mixB;
orp.setResultProviderEndpoint(getDefaultEndpoint());
getEndpointAttribute(orp).setValue(getDefaultEndpoint());
}
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Publisher_occiRetrieve_method
/**
* Called when this Publisher instance must be retrieved.
*/
@Override
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Publisher_occiUpdate_method
/**
* Called when this Publisher instance is completely updated.
*/
@Override
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code PublisherocciDelete_method
/**
* Called when this Publisher instance will be deleted.
*/
@Override
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
if (ComponentManager.isConnectedToCompute(this)) {
this.stop();
this.undeploy();
}
}
// End of user code
//
// Publisher actions.
//
// Start of user code Publisher_Kind_deploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
public void deploy() {
LOGGER.debug("Action deploy() called on " + this);
compMan.deploy();
// TODO: Implement how to deploy this publisher.
}
// End of user code
// Start of user code Publisher_Kind_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@Override
public void stop() {
LOGGER.debug("Action stop() called on " + this);
compMan.stop();
// TODO: Implement how to stop this publisher.
}
// End of user code
// Start of user code Publisher_Kind_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void start() {
setRuntimeInformation();
System.out.println(this.attributes);
LOGGER.debug("Action start() called on " + this);
compMan.start();
removeRuntimeInformation();
System.out.println(this.attributes);
}
// End of user code
// Start of user code Publisher_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void configure() {
LOGGER.debug("Action configure() called on " + this);
compMan.configure();
// TODO: Implement how to configure this publisher.
}
// End of user code
// Start of user code Publisher_Kind_undeploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@Override
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
compMan.undeploy();
// TODO: Implement how to undeploy this publisher.
}
// End of user code
private MixinBase getMartMixin() {
for (MixinBase mixinBase : this.getParts()) {
if (mixinBase instanceof Occiresultprovider) {
LOGGER.info("MartPublisher Mixin found for Publisher:" + this.title);
return mixinBase;
}
}
return null;
}
private List<Monitorableproperty> getMonitoringProperties(Sensor sens) {
LinkedList<Monitorableproperty> monProps = new LinkedList<Monitorableproperty>();
for (Link link : sens.getLinks()) {
if (link instanceof Monitorableproperty) {
monProps.add((Monitorableproperty) link);
}
}
return monProps;
}
private void setRuntimeInformation() {
sensor = getSensor();
AttributeState sensorAttr = factory.createAttributeState();
sensorAttr.setName("sensor");
sensorAttr.setValue(sensor.getLocation());
System.out.println("Sensor: " + sensor);
this.attributes.add(sensorAttr);
workaround.add(sensorAttr);
monProp = getMonProp(sensor);
AttributeState monPropAttr = factory.createAttributeState();
monPropAttr.setName("monitorable.property");
monPropAttr.setValue(monProp.getLocation());
System.out.println("MonProp: " + monProp);
this.attributes.add(monPropAttr);
workaround.add(monPropAttr);
AttributeState monPropNameAttr = factory.createAttributeState();
monPropNameAttr.setName("monitorable.property.property");
monPropNameAttr.setValue(monProp.getMonitoringProperty());
this.attributes.add(monPropNameAttr);
workaround.add(monPropNameAttr);
monObject = monProp.getTarget();
AttributeState monObjectAttr = factory.createAttributeState();
monObjectAttr.setName("monitorable.property.target");
monObjectAttr.setValue(monObject.getLocation());
this.attributes.add(monObjectAttr);
workaround.add(monObjectAttr);
}
private AttributeState getEndpointAttribute(Occiresultprovider orp) {
for (AttributeState as : orp.getAttributes()) {
if (as.getName().equals("result.provider.endpoint")) {
return as;
}
}
AttributeState as = OCCIFactory.eINSTANCE.createAttributeState();
as.setName("result.provider.endpoint");
orp.getAttributes().add(as);
return as;
}
private boolean rspIsDefined() {
MixinBase mixB = getMartMixin();
if (mixB != null) {
Occiresultprovider orp = (Occiresultprovider) mixB;
if (orp.getResultProviderEndpoint() == null || orp.getResultProviderEndpoint().equals("")) {
return false;
}
for (AttributeState as : this.getAttributes()) {
if (as.getName().equals("occi.result.provider.endpoint")) {
if (as.getValue() == null || as.getValue().equals("")) {
return false;
}
}
}
for (AttributeState as : orp.getAttributes()) {
if (as.getName().equals("occi.result.provider.endpoint")) {
if (as.getValue() == null || as.getValue().equals("")) {
return false;
}
}
}
}
return true;
}
private String getDefaultEndpoint() {
String defaultEndpoint = new PropertiesHelper().getProperties().getProperty("default_endpoint");
if (defaultEndpoint == null || defaultEndpoint.equals("")) {
return "localhost";
}
System.out.println("Using default endpoint: " + defaultEndpoint);
return defaultEndpoint;
}
private Sensor getSensor() {
for (Link link : this.getRlinks()) {
if (link.getSource() instanceof Sensor) {
return ((Sensor) link.getSource());
}
}
throw new NoSuchElementException("No containing sensor found!");
}
private Monitorableproperty getMonProp(Sensor sensor) {
for (Link link : sensor.getLinks()) {
if (link instanceof Monitorableproperty) {
return ((Monitorableproperty) link);
}
}
throw new NoSuchElementException("No monitorableproperty found in sensor!");
}
private void removeRuntimeInformation() {
for (AttributeState work : workaround) {
this.attributes.remove(work);
}
}
private String getContainingSensorLocation() {
for (Link link : this.getRlinks()) {
if (link.getSource() instanceof Sensor) {
return link.getSource().getLocation();
}
}
return "No containing sensor found";
}
private Sensor getContainingSensor() {
for (Link link : this.getRlinks()) {
if (link.getSource() instanceof Sensor) {
return (Sensor) link.getSource();
}
}
LOGGER.info("No containing Sensor found");
throw new NoSuchElementException();
}
}
/**
* Copyright (c) 2016-2017 Inria
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Mon Dec 17 14:48:34 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.core.MixinBase;
import org.modmacao.cm.ConfigurationManagementTool;
import org.modmacao.cm.ansible.AnsibleCMTool;
import org.modmacao.occi.platform.Component;
import org.modmacao.occi.platform.Componentlink;
import org.modmacao.occi.platform.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.ugoe.cs.rwm.mocci.connector.util.SensorSimulation;
/**
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: sensor - title: Sensor
* Component
*/
public class SensorConnector extends monitoring.impl.SensorImpl {
private Thread simulation;
private ConfigurationManagementTool cmtool = new AnsibleCMTool();
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(SensorConnector.class);
// Start of user code Sensorconnector_constructor
/**
* Constructs a sensor connector.
*/
SensorConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code SensorocciCreate
/**
* Called when this Sensor instance is completely created.
*/
@Override
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Sensor_occiRetrieve_method
/**
* Called when this Sensor instance must be retrieved.
*/
@Override
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Sensor_occiUpdate_method
/**
* Called when this Sensor instance is completely updated.
*/
@Override
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
if (simulation != null) {
simulation.stop();
System.out.println("Restarting Sensor Simulation after attribute update!");
SensorSimulation sim = new SensorSimulation(this);
simulation = new Thread(sim);
simulation.start();
}
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code SensorocciDelete_method
/**
* Called when this Sensor instance will be deleted.
*/
@Override
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
this.stop();
this.undeploy();
// TODO: Implement this callback or remove this method.
}
// End of user code
//
// Sensor actions.
//
// Start of user code Sensor_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void configure() {
int status = -1;
LOGGER.debug("Action configure() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.DEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=deployed, action=\"configure\")...");
for (Component component : this.getConnectedComponents()) {
component.configure();
}
status = cmtool.configure(this);
if (status == 0) {
setOcciAppState(Status.INACTIVE);
} else {
setOcciAppState(Status.ERROR);
}
break;
default:
break;
}
}
// End of user code
// Start of user code Sensor_Kind_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void start() {
int status = -1;
LOGGER.debug("Action start() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.INACTIVE_VALUE:
LOGGER.debug("Fire transition(state=inactive, action=\"start\")...");
for (Component component : this.getConnectedComponents()) {
component.start();
}
if (needsSimulation()) {
SensorSimulation sim = new SensorSimulation(this);
simulation = new Thread(sim);
simulation.start();
setOcciAppState(Status.ACTIVE);
return;
}
status = cmtool.start(this);
if (status == 0) {
setOcciAppState(Status.ACTIVE);
} else {
setOcciAppState(Status.ERROR);
}
break;
case Status.UNDEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=undeployed, action=\"start\")...");
// First deploy components
for (Component component : this.getConnectedComponents()) {
component.deploy();
}
this.deploy();
// then configure them
for (Component component : this.getConnectedComponents()) {
component.configure();
}
this.configure();
// then start them
for (Component component : this.getConnectedComponents()) {
component.start();
}
if (needsSimulation()) {
SensorSimulation sim = new SensorSimulation(this);
simulation = new Thread(sim);
simulation.start();
setOcciAppState(Status.ACTIVE);
return;
}
status = cmtool.start(this);
if (status == 0) {
setOcciAppState(Status.ACTIVE);
} else {
setOcciAppState(Status.ERROR);
}
break;
default:
break;
}
}
// End of user code
// Start of user code Sensor_Kind_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@Override
public void stop() {
int status = -1;
LOGGER.debug("Action stop() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.ACTIVE_VALUE:
LOGGER.debug("Fire transition(state=active, action=\"stop\")...");
for (Component component : this.getConnectedComponents()) {
component.stop();
}
if (simulation != null) {
simulation.stop();
setOcciAppState(Status.INACTIVE);
}
status = cmtool.stop(this);
if (status == 0) {
setOcciAppState(Status.INACTIVE);
} else {
setOcciAppState(Status.ERROR);
}
break;
default:
break;
}
// TODO: Implement how to stop this sensor.
}
// End of user code
// Start of user code Sensor_Kind_deploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
public void deploy() {
int status = -1;
LOGGER.debug("Action deploy() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.UNDEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=undeployed, action=\"deploy\")...");
for (Component component : this.getConnectedComponents()) {
component.deploy();
}
status = cmtool.deploy(this);
if (status == 0) {
setOcciAppState(Status.DEPLOYED);
} else {
setOcciAppState(Status.ERROR);
}
break;
default:
break;
}
}
// End of user code
// Start of user code Sensor_Kind_undeploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@Override
public void undeploy() {
int status = -1;
LOGGER.debug("Action undeploy() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.ACTIVE_VALUE:
LOGGER.debug("Fire transition(state=active, action=\"undeploy\")...");
for (Component component : this.getConnectedComponents()) {
component.stop();
}
this.stop();
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
status = cmtool.undeploy(this);
if (status == 0) {
setOcciAppState(Status.UNDEPLOYED);
} else {
setOcciAppState(Status.ERROR);
}
break;
case Status.INACTIVE_VALUE:
LOGGER.debug("Fire transition(state=inactive, action=\"undeploy\")...");
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
status = cmtool.undeploy(this);
if (status == 0) {
setOcciAppState(Status.UNDEPLOYED);
} else {
setOcciAppState(Status.ERROR);
}
break;
case Status.DEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=deployed, action=\"undeploy\")...");
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
status = cmtool.undeploy(this);
if (status == 0) {
setOcciAppState(Status.UNDEPLOYED);
} else {
setOcciAppState(Status.ERROR);
}
break;
case Status.ERROR_VALUE:
LOGGER.debug("Fire transition(state=error, action=\"undeploy\")...");
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
status = cmtool.undeploy(this);
if (status == 0) {
setOcciAppState(Status.UNDEPLOYED);
} else {
setOcciAppState(Status.ERROR);
}
break;
default:
break;
}
}
// End of user code
private List<Component> getConnectedComponents() {
LinkedList<Component> connectedComponents = new LinkedList<Component>();
for (Link link : this.getLinks()) {
if (link instanceof Componentlink) {
connectedComponents.add((Component) link.getTarget());
}
}
return connectedComponents;
}
public MixinBase getSimulationMixin() {
for (MixinBase mixB : this.getParts()) {
if (mixB.getMixin().getTerm().toLowerCase().equals("sensorsim")) {
return mixB;
}
}
return null;
}
private boolean needsSimulation() {
if (getSimulationMixin() != null) {
int simLevel = Integer.parseInt(SensorSimulation.getAttribute(getSimulationMixin(), "sim.level"));
if (simLevel == 0) {
if (simulation == null || simulation.isAlive() == false) {
return true;
}
}
}
return false;
}
}
/*******************************************************************************
* Copyright (c) 2019 University of Goettingen.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Johannes Erbel <johannes.erbel@cs.uni-goettingen.de>
*******************************************************************************/
/**
*
*/
/**
* Main package for mocci connector.
*
* @author erbel
*
*/
package de.ugoe.cs.rwm.mocci.connector;
\ No newline at end of file