Skip to content

Commit

Permalink
Merge pull request #121 from eclipse-researchlabs/GitlabCommitMonitor
Browse files Browse the repository at this point in the history
Gitlab commit monitor
  • Loading branch information
schlotze authored May 18, 2022
2 parents 61b8ad3 + a58fba3 commit 772e897
Show file tree
Hide file tree
Showing 29 changed files with 1,205 additions and 591 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish-container-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
env:
CONTAINER_REGISTRY_USERNAME: ${GITHUB_ACTOR}
CONTAINER_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SMARTCLIDE_CONTEXT_GITLAB_API_TOKEN: ${{ secrets.SMARTCLIDE_CONTEXT_GITLAB_API_TOKEN }}

steps:
- name: Checkout
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ jobs:

- name: Run Tests
run: mvn --file pom.xml --batch-mode test
env:
SMARTCLIDE_CONTEXT_GITLAB_API_TOKEN: ${{ secrets.SMARTCLIDE_CONTEXT_GITLAB_API_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@
*/


import de.atb.context.common.Configuration;
import de.atb.context.common.exceptions.ConfigurationException;
import de.atb.context.monitoring.config.models.*;
import de.atb.context.tools.ontology.AmIMonitoringConfiguration;
import org.simpleframework.xml.core.Persister;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.atb.context.monitoring.config.models.IMonitoringConfiguration;
import de.atb.context.monitoring.config.models.Index;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import de.atb.context.tools.ontology.AmIMonitoringConfiguration;
import de.atb.context.common.Configuration;
import de.atb.context.common.exceptions.ConfigurationException;
import de.atb.context.monitoring.config.models.Config;
import de.atb.context.monitoring.config.models.DataSource;
import de.atb.context.monitoring.config.models.Interpreter;
import de.atb.context.monitoring.config.models.Monitor;

/**
* Settings
*
Expand All @@ -42,35 +36,35 @@
*/
public final class MonitoringConfiguration extends Configuration<Config> implements IMonitoringConfiguration {

private static volatile Map<String, MonitoringConfiguration> settings = new HashMap<>();
private static final String DefaultFileName = "monitoring-config.xml";
private static final Map<String, MonitoringConfiguration> SETTINGS = new HashMap<>();
private static final String DEFAULT_FILE_NAME = "monitoring-config.xml";

public static MonitoringConfiguration getInstance() {
if (settings.get(DefaultFileName) == null) {
settings.put(DefaultFileName, new MonitoringConfiguration(DefaultFileName));
if (SETTINGS.get(DEFAULT_FILE_NAME) == null) {
SETTINGS.put(DEFAULT_FILE_NAME, new MonitoringConfiguration(DEFAULT_FILE_NAME));
}
return settings.get(DefaultFileName);
return SETTINGS.get(DEFAULT_FILE_NAME);
}

public static MonitoringConfiguration getInstance(final AmIMonitoringConfiguration config) {
if (settings.get(config) == null) {
settings.put(config.getId(), new MonitoringConfiguration(config));
if (SETTINGS.get(config) == null) {
SETTINGS.put(config.getId(), new MonitoringConfiguration(config));
}
return settings.get(config.getId());
return SETTINGS.get(config.getId());
}

public static MonitoringConfiguration getInstance(final String configFileName) {
if (settings.get(configFileName) == null) {
settings.put(configFileName, new MonitoringConfiguration(configFileName));
if (SETTINGS.get(configFileName) == null) {
SETTINGS.put(configFileName, new MonitoringConfiguration(configFileName));
}
return settings.get(configFileName);
return SETTINGS.get(configFileName);
}

public static MonitoringConfiguration getInstance(final String configFileName, final String configFilePath) {
if (settings.get(configFileName) == null) {
settings.put(configFileName, new MonitoringConfiguration(configFileName, configFilePath));
if (SETTINGS.get(configFileName) == null) {
SETTINGS.put(configFileName, new MonitoringConfiguration(configFileName, configFilePath));
}
return settings.get(configFileName);
return SETTINGS.get(configFileName);
}

private MonitoringConfiguration(final String givenName, final String givenPath) {
Expand All @@ -88,23 +82,19 @@ private MonitoringConfiguration(final AmIMonitoringConfiguration config) {
protected void readConfigurationFile() {
InputStream is = null;
try {
final Serializer serializer = new Persister();

String drmHandle = sysCaller.openDRMobject("monitoring-config.xml", configurationLookupPath,"read");
final String drmHandle = sysCaller.openDRMobject(configurationFileName, configurationLookupPath, "read");
if (drmHandle != null) {
byte[] readConfig = sysCaller.getDRMobject("monitoring-config.xml", configurationLookupPath);
final byte[] readConfig = sysCaller.getDRMobject(configurationFileName, configurationLookupPath);
if (readConfig != null) {
is = new ByteArrayInputStream(readConfig);
this.configurationBean = serializer.read(
this.configurationClass, is);
this.configurationBean = new Persister().read(this.configurationClass, is);
is.close();
logger.info("" + this.configurationFileName + " loaded!");
logger.info("{} loaded!", configurationFileName);
}
sysCaller.closeDRMobject(drmHandle);
}
} catch (final Exception e) {
logger.error("Could not serialize the " + configurationName
+ " file: " + this.configurationFileName, e);
logger.error("Could not serialize the {} file {}", configurationName, configurationFileName, e);
} finally {
if (is != null) {
try {
Expand Down Expand Up @@ -170,15 +160,25 @@ public void checkConsistency() throws ConfigurationException {
}

if (getDataSource(monitor.getDataSourceId()) == null) {
throw new ConfigurationException("DataSource '%s' for Monitor '%s' is not configured", monitor.getDataSourceId(),
monitor.getId());
throw new ConfigurationException(
"DataSource '%s' for Monitor '%s' is not configured",
monitor.getDataSourceId(),
monitor.getId()
);
}
if (getInterpreter(monitor.getInterpreterId()) == null) {
throw new ConfigurationException("Interpreter '%s' for Monitor '%s' is not configured", monitor.getInterpreterId(),
monitor.getId());
throw new ConfigurationException(
"Interpreter '%s' for Monitor '%s' is not configured",
monitor.getInterpreterId(),
monitor.getId()
);
}
if (getIndex(monitor.getIndexId()) == null) {
throw new ConfigurationException("Index '%s' for Monitor '%s' is not configured", monitor.getIndexId(), monitor.getId());
throw new ConfigurationException(
"Index '%s' for Monitor '%s' is not configured",
monitor.getIndexId(),
monitor.getId()
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,92 +15,108 @@
*/


import java.net.URI;

import de.atb.context.common.authentication.Credentials;
import de.atb.context.monitoring.config.models.DataSource;
import de.atb.context.monitoring.config.models.DataSourceType;
import de.atb.context.monitoring.models.IMessageBroker;
import thewebsemantic.Namespace;
import thewebsemantic.RdfType;

import java.io.Serializable;
import java.net.URI;

/**
* MessageBrokerDataSource
*
* @author scholze
* @version $LastChangedRevision: 156 $
*
*/
@RdfType("MessageBrokerDataSource")
@Namespace("http://atb-bremen.de/")
public class MessageBrokerDataSource extends DataSource {

private static final long serialVersionUID = 3490943354053238739L;
public MessageBrokerDataSource() {
}

public MessageBrokerDataSource(final DataSource base) {
this.id = base.getId();
this.monitor = base.getMonitor();
this.options = base.getOptions();
this.type = base.getType().toString();
this.uri = base.getUri();
}

@Override
public final DataSourceType getType() {
return DataSourceType.MessageBroker;
}

public final String getMessageBrokerServer() {
return this.getOptionValue(MessageBrokerDataSourceOptions.MessageBrokerServer, true);
}

public MessageBrokerDataSource() {
}
public final Integer getMessageBrokerPort() {
return this.getOptionValue(MessageBrokerDataSourceOptions.MessageBrokerPort, true);
}

public MessageBrokerDataSource(final DataSource base) {
this.id = base.getId();
this.monitor = base.getMonitor();
this.options = base.getOptions();
this.type = base.getType().toString();
this.uri = base.getUri();
}
public final String getUserName() {
return this.getOptionValue(MessageBrokerDataSourceOptions.UserName, true);
}

@Override
public final DataSourceType getType() {
return DataSourceType.MessageBroker;
}
public final String getPassword() {
return this.getOptionValue(MessageBrokerDataSourceOptions.Password, true);
}

public final String getMessageBrokerServer() {
return this.getOptionValue(MessageBrokerDataSourceOptions.MessageBrokerServer, true);
}
public final String getIncomingExchange() {
return this.getOptionValue(MessageBrokerDataSourceOptions.IncomingExchange, true);
}

public final Integer getMessageBrokerPort() {
return this.getOptionValue(MessageBrokerDataSourceOptions.MessageBrokerPort, true);
public final String getIncomingTopic() {
return this.getOptionValue(MessageBrokerDataSourceOptions.IncomingTopic, true);
}

public final String getUserName() {
return this.getOptionValue(MessageBrokerDataSourceOptions.UserName, true);
}
public final boolean isIncomingDurable() {
final Serializable value = this.getOptionValue(MessageBrokerDataSourceOptions.IncomingDurable, false);
return value != null && (boolean) value;
}

public final String getPassword() {
return this.getOptionValue(MessageBrokerDataSourceOptions.Password, true);
}
public final String getOutgoingExchange() {
return this.getOptionValue(MessageBrokerDataSourceOptions.OutgoingExchange, true);
}

public final String getExchange() {
return this.getOptionValue(MessageBrokerDataSourceOptions.Exchange, true);
public final String getOutgoingTopic() {
return this.getOptionValue(MessageBrokerDataSourceOptions.OutgoingTopic, true);
}

public final String getTopic() {
return this.getOptionValue(MessageBrokerDataSourceOptions.Topic, true);
public final String getOutgoingQueue() {
return this.getOptionValue(MessageBrokerDataSourceOptions.OutgoingQueue, true);
}

public final String getDleTopic() {
return this.getOptionValue(MessageBrokerDataSourceOptions.DleTopic, true);
public final boolean isOutgoingDurable() {
final Serializable value = this.getOptionValue(MessageBrokerDataSourceOptions.OutgoingDurable, false);
return value != null && (boolean) value;
}

public final Credentials getCredentials() {
String userName = this.getUserName();
String password = this.getPassword();
return new Credentials(userName, password);
}
String userName = this.getUserName();
String password = this.getPassword();
return new Credentials(userName, password);
}

public final IMessageBroker toMessageBroker() {
final URI myUri = URI.create(uri);
public final IMessageBroker toMessageBroker() {
final URI myUri = URI.create(uri);
final Credentials myCredentials = getCredentials();
return new IMessageBroker() {
return new IMessageBroker() {

@Override
public URI getURI() {
return myUri;
}
@Override
public URI getURI() {
return myUri;
}

@Override
public Credentials getCredentials() {
return myCredentials;
}
};
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ public enum MessageBrokerDataSourceOptions implements IDataSourceOptionValue {

Password("password", String.class),

Exchange("exchange", String.class),
IncomingExchange("incoming-exchange", String.class),

Topic("topic", String.class),
IncomingTopic("incoming-topic", String.class),

DleTopic("dle-topic", String.class);
IncomingDurable("incoming-durable", Boolean.class),

OutgoingExchange("outgoing-exchange", String.class),

OutgoingTopic("outgoing-topic", String.class),

OutgoingQueue("outgoing-queue", String.class),

OutgoingDurable("outgoing-durable", Boolean.class);

private final String key;
private final Class<? extends Serializable> valueType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/


import java.net.URI;

import de.atb.context.common.authentication.Credentials;
import de.atb.context.monitoring.config.models.DataSource;
import de.atb.context.monitoring.config.models.DataSourceType;
import de.atb.context.monitoring.models.IWebService;
import thewebsemantic.Namespace;
import thewebsemantic.RdfType;
import de.atb.context.common.authentication.Credentials;

import java.net.URI;

/**
* WebServiceDataSource
Expand Down Expand Up @@ -68,6 +68,10 @@ public final String getPassword() {
return this.getOptionValue(WebServiceDataSourceOptions.Password, true);
}

public final Long getStartDelay() {
return this.getOptionValue(WebServiceDataSourceOptions.StartDelay, true);
}

public final String getMachineId() {
return this.getOptionValue(WebServiceDataSourceOptions.MachineId, true);
}
Expand All @@ -78,10 +82,6 @@ public final Credentials getCredentials() {
return new Credentials(userName, password);
}

public final Long getStartDelay() {
return this.getOptionValue(WebServiceDataSourceOptions.StartDelay, true);
}

public final IWebService toWebService() {
final URI myUri = URI.create(uri);
final Credentials myCredentials = getCredentials();
Expand Down
Loading

0 comments on commit 772e897

Please sign in to comment.