This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new version 0.20.0: Updated REST-SDK version 1.1.0, updated MQTT-SDK …
…version 1.0.2, updated jackson dependencies 2.9.8, optimized operation handling
- Loading branch information
Showing
43 changed files
with
2,793 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
common/src/main/java/com/telekom/cot/device/agent/common/exc/DeviceServiceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.telekom.cot.device.agent.common.exc; | ||
|
||
public class DeviceServiceException extends AbstractAgentException { | ||
|
||
/** | ||
* serialVersionUID | ||
*/ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public DeviceServiceException(String message, Throwable throwable, boolean enableSuppression, | ||
boolean writableStackTrace) { | ||
super(message, throwable, enableSuppression, writableStackTrace); | ||
} | ||
|
||
public DeviceServiceException(String message, Throwable throwable) { | ||
super(message, throwable); | ||
} | ||
|
||
public DeviceServiceException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...on/src/main/java/com/telekom/cot/device/agent/common/exc/MeasurementServiceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.telekom.cot.device.agent.common.exc; | ||
|
||
public class MeasurementServiceException extends AbstractAgentException { | ||
|
||
/** | ||
* serialVersionUID | ||
*/ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public MeasurementServiceException(String message, Throwable throwable, boolean enableSuppression, | ||
boolean writableStackTrace) { | ||
super(message, throwable, enableSuppression, writableStackTrace); | ||
} | ||
|
||
public MeasurementServiceException(String message, Throwable throwable) { | ||
super(message, throwable); | ||
} | ||
|
||
public MeasurementServiceException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...c/main/java/com/telekom/cot/device/agent/common/exc/OperationHandlerServiceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.telekom.cot.device.agent.common.exc; | ||
|
||
public class OperationHandlerServiceException extends AbstractAgentException { | ||
|
||
/** | ||
* serialVersionUID | ||
*/ | ||
private static final long serialVersionUID = 7752808930953738383L; | ||
|
||
public OperationHandlerServiceException(String message) { | ||
super(message); | ||
} | ||
|
||
public OperationHandlerServiceException(String message, Throwable throwable) { | ||
super(message, throwable); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...rc/test/java/com/telekom/cot/device/agent/common/exc/MeasurementServiceExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.telekom.cot.device.agent.common.exc; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class MeasurementServiceExceptionTest { | ||
|
||
@Test | ||
public void test() { | ||
MeasurementServiceException measurementServiceException = new MeasurementServiceException("testMessage"); | ||
Assert.assertEquals("testMessage", measurementServiceException.getMessage()); | ||
|
||
measurementServiceException = new MeasurementServiceException("testMessage", new Throwable()); | ||
Assert.assertEquals("testMessage", measurementServiceException.getMessage()); | ||
|
||
measurementServiceException = new MeasurementServiceException("testMessage", new Throwable(), true, true); | ||
Assert.assertEquals("testMessage", measurementServiceException.getMessage()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...st/java/com/telekom/cot/device/agent/common/exc/OperationHandlerServiceExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.telekom.cot.device.agent.common.exc; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class OperationHandlerServiceExceptionTest { | ||
|
||
@Test | ||
public void test(){ | ||
OperationHandlerServiceException exception = new OperationHandlerServiceException("message"); | ||
Assert.assertThat(exception.getMessage(), Matchers.equalTo("message")); | ||
|
||
exception = new OperationHandlerServiceException("message", new Exception()); | ||
Assert.assertThat(exception.getMessage(), Matchers.equalTo("message")); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...a/com/telekom/cot/device/agent/operation/handler/ConfigurationUpdateOperationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.telekom.cot.device.agent.operation.handler; | ||
|
||
import static com.telekom.cot.device.agent.common.util.AssertionUtil.*; | ||
|
||
import java.util.Objects; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.telekom.cot.device.agent.common.configuration.ConfigurationManager; | ||
import com.telekom.cot.device.agent.common.exc.AbstractAgentException; | ||
import com.telekom.cot.device.agent.common.exc.OperationHandlerServiceException; | ||
import com.telekom.cot.device.agent.common.injection.Inject; | ||
import com.telekom.cot.device.agent.inventory.InventoryService; | ||
import com.telekom.cot.device.agent.operation.operations.ConfigurationUpdateOperation; | ||
import com.telekom.cot.device.agent.platform.objects.operation.Operation.OperationStatus; | ||
import com.telekom.cot.device.agent.service.AbstractAgentService; | ||
import com.telekom.cot.device.agent.system.SystemService; | ||
import com.telekom.cot.device.agent.system.properties.ConfigurationProperties; | ||
|
||
|
||
public class ConfigurationUpdateOperationHandler extends AbstractAgentService implements OperationHandlerService<ConfigurationUpdateOperation> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationUpdateOperationHandler.class); | ||
|
||
@Inject | ||
private ConfigurationManager configurationManager; | ||
|
||
@Inject | ||
private SystemService systemService; | ||
|
||
@Inject | ||
private InventoryService inventoryService; | ||
|
||
@Override | ||
public Class<ConfigurationUpdateOperation> getSupportedOperationType() { | ||
return ConfigurationUpdateOperation.class; | ||
} | ||
|
||
@Override | ||
public OperationStatus execute(ConfigurationUpdateOperation operation) throws AbstractAgentException { | ||
assertNotNull(operation, OperationHandlerServiceException.class, LOGGER, "no ConfigurationUpdateOperation given to execute"); | ||
LOGGER.debug("execute ConfigurationUpdateOperation {}", operation.getProperties()); | ||
|
||
String configuration = operation.getConfiguration(); | ||
assertNotEmpty(configuration, OperationHandlerServiceException.class, LOGGER, "config value expected (is null or empty)"); | ||
|
||
LOGGER.info("update agent configuration {}", configuration); | ||
configurationManager.updateConfiguration(configuration); | ||
|
||
// update the managedObjects c8y_Configuration Fragment | ||
ConfigurationProperties configurationProperties = systemService.getProperties(ConfigurationProperties.class); | ||
if (Objects.nonNull(configurationProperties)) { | ||
configurationProperties.setConfig(configuration); | ||
} | ||
|
||
inventoryService.updateDevice(); | ||
return OperationStatus.SUCCESSFUL; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...src/main/java/com/telekom/cot/device/agent/operation/handler/OperationHandlerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.telekom.cot.device.agent.operation.handler; | ||
|
||
import com.telekom.cot.device.agent.common.exc.AbstractAgentException; | ||
import com.telekom.cot.device.agent.platform.objects.operation.Operation; | ||
import com.telekom.cot.device.agent.platform.objects.operation.Operation.OperationStatus; | ||
import com.telekom.cot.device.agent.service.AgentService; | ||
|
||
|
||
public interface OperationHandlerService<T extends Operation> extends AgentService { | ||
|
||
/** | ||
* get the type of the operation this handler supports | ||
* @return type of supported operation | ||
*/ | ||
public Class<T> getSupportedOperationType(); | ||
|
||
/** | ||
* executes the given operation and returns the execution status | ||
* @param operation the operation to execute | ||
* @return the status of operation execution | ||
* @throws AbstractAgentException | ||
*/ | ||
public OperationStatus execute(T operation) throws AbstractAgentException; | ||
} |
22 changes: 22 additions & 0 deletions
22
...main/java/com/telekom/cot/device/agent/operation/handler/SoftwareUpdateConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.telekom.cot.device.agent.operation.handler; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import com.telekom.cot.device.agent.common.ChecksumAlgorithm; | ||
import com.telekom.cot.device.agent.common.annotations.ConfigurationPath; | ||
import com.telekom.cot.device.agent.common.configuration.Configuration; | ||
|
||
@ConfigurationPath("agent.operations.softwareUpdate") | ||
public class SoftwareUpdateConfiguration implements Configuration { | ||
|
||
@NotNull | ||
private ChecksumAlgorithm checksumAlgorithm; | ||
|
||
public ChecksumAlgorithm getChecksumAlgorithm() { | ||
return checksumAlgorithm; | ||
} | ||
|
||
public void setChecksumAlgorithm(ChecksumAlgorithm checksumAlgorithm) { | ||
this.checksumAlgorithm = checksumAlgorithm; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...n/java/com/telekom/cot/device/agent/operation/handler/SoftwareUpdateOperationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.telekom.cot.device.agent.operation.handler; | ||
|
||
import static com.telekom.cot.device.agent.common.util.AssertionUtil.*; | ||
|
||
import java.net.URL; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.telekom.cot.device.agent.common.exc.AbstractAgentException; | ||
import com.telekom.cot.device.agent.common.exc.OperationHandlerServiceException; | ||
import com.telekom.cot.device.agent.common.injection.Inject; | ||
import com.telekom.cot.device.agent.operation.operations.SoftwareUpdateOperation; | ||
import com.telekom.cot.device.agent.operation.softwareupdate.SoftwareInstaller; | ||
import com.telekom.cot.device.agent.operation.softwareupdate.SoftwareInstallerFactory; | ||
import com.telekom.cot.device.agent.platform.PlatformService; | ||
import com.telekom.cot.device.agent.platform.objects.operation.Operation.OperationStatus; | ||
import com.telekom.cot.device.agent.service.AbstractAgentService; | ||
import com.telekom.cot.device.agent.system.properties.Software; | ||
|
||
|
||
public class SoftwareUpdateOperationHandler extends AbstractAgentService implements OperationHandlerService<SoftwareUpdateOperation> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(SoftwareUpdateOperationHandler.class); | ||
|
||
private SoftwareInstaller softwareInstaller; | ||
|
||
@Inject | ||
private PlatformService platformService; | ||
|
||
@Inject | ||
private SoftwareUpdateConfiguration configuration; | ||
|
||
@Override | ||
public void start() throws AbstractAgentException { | ||
softwareInstaller = SoftwareInstallerFactory.getInstance(); | ||
super.start(); | ||
} | ||
|
||
@Override | ||
public Class<SoftwareUpdateOperation> getSupportedOperationType() { | ||
return SoftwareUpdateOperation.class; | ||
} | ||
|
||
@Override | ||
public OperationStatus execute(SoftwareUpdateOperation operation) throws AbstractAgentException { | ||
assertNotNull(operation, OperationHandlerServiceException.class, LOGGER, "no software update operation given"); | ||
LOGGER.info("execute software update operation {}", operation.getProperties()); | ||
|
||
URL url = getSoftwareDownloadURL(operation); | ||
LOGGER.info("download agent software by URL {}", url); | ||
softwareInstaller.downloadSoftware(platformService, url, configuration.getChecksumAlgorithm()); | ||
|
||
LOGGER.info("install downloaded agent software"); | ||
softwareInstaller.installSoftware(); | ||
return OperationStatus.EXECUTING; | ||
} | ||
|
||
private URL getSoftwareDownloadURL(SoftwareUpdateOperation operation) throws AbstractAgentException { | ||
Software software = operation.getSoftware(); | ||
assertNotNull(software, OperationHandlerServiceException.class, LOGGER, "no software information found @ software update operation"); | ||
assertNotEmpty(software.getVersion(), OperationHandlerServiceException.class, LOGGER, "software version is missed"); | ||
|
||
try { | ||
return new URL(software.getUrl()); | ||
} catch (Exception e) { | ||
throw createExceptionAndLog(OperationHandlerServiceException.class, LOGGER, "can't get download url from software update operation", e); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/com/telekom/cot/device/agent/operation/handler/TestOperationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.telekom.cot.device.agent.operation.handler; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Positive; | ||
|
||
import com.telekom.cot.device.agent.common.annotations.ConfigurationPath; | ||
import com.telekom.cot.device.agent.common.configuration.Configuration; | ||
|
||
@ConfigurationPath("agent.operations.testOperation") | ||
public class TestOperationConfiguration implements Configuration { | ||
|
||
@NotNull @Positive | ||
private int delay; | ||
|
||
public int getDelay() { | ||
return delay; | ||
} | ||
|
||
public void setDelay(int delay) { | ||
this.delay = delay; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...on/src/main/java/com/telekom/cot/device/agent/operation/handler/TestOperationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.telekom.cot.device.agent.operation.handler; | ||
|
||
import static com.telekom.cot.device.agent.common.util.AssertionUtil.*; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.telekom.cot.device.agent.common.exc.AbstractAgentException; | ||
import com.telekom.cot.device.agent.common.exc.OperationHandlerServiceException; | ||
import com.telekom.cot.device.agent.common.injection.Inject; | ||
import com.telekom.cot.device.agent.operation.operations.TestOperation; | ||
import com.telekom.cot.device.agent.operation.operations.TestOperation.GivenStatus; | ||
import com.telekom.cot.device.agent.platform.objects.operation.Operation.OperationStatus; | ||
import com.telekom.cot.device.agent.service.AbstractAgentService; | ||
|
||
public class TestOperationHandler extends AbstractAgentService implements OperationHandlerService<TestOperation> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(TestOperationHandler.class); | ||
|
||
@Inject | ||
TestOperationConfiguration configuration; | ||
|
||
@Override | ||
public Class<TestOperation> getSupportedOperationType() { | ||
return TestOperation.class; | ||
} | ||
|
||
@Override | ||
public OperationStatus execute(TestOperation operation) throws AbstractAgentException { | ||
assertNotNull(operation, OperationHandlerServiceException.class, LOGGER, "no TestOperation given to execute"); | ||
LOGGER.debug("execute TestOperation {}", operation.getProperties()); | ||
|
||
// delay execution | ||
try { | ||
TimeUnit.SECONDS.sleep(configuration.getDelay()); | ||
} catch (Exception e) { | ||
throw createExceptionAndLog(OperationHandlerServiceException.class, LOGGER, "can't delay the execution", e); | ||
} | ||
|
||
// get and check given status | ||
GivenStatus givenStatus = operation.getGivenStatus(); | ||
if(Objects.isNull(givenStatus)) { | ||
throw createExceptionAndLog(OperationHandlerServiceException.class, LOGGER, "can't get given status from operation"); | ||
} | ||
|
||
// perform execution with given status | ||
switch (givenStatus) { | ||
case GIVEN_SUCCESSFUL: | ||
LOGGER.info("executed TestOperation with given status 'SUCCESSFUL'"); | ||
return OperationStatus.SUCCESSFUL; | ||
|
||
case GIVEN_FAILED_BY_STATUS: | ||
LOGGER.info("executed TestOperation with given status 'FAILED'"); | ||
return OperationStatus.FAILED; | ||
|
||
case GIVEN_FAILED_BY_EXCEPTION: | ||
LOGGER.info("executed TestOperation with given status 'FAILED_BY_EXCEPTION'"); | ||
throw new OperationHandlerServiceException("execution is failed by exception"); | ||
|
||
default: | ||
LOGGER.info("can't execute TestOperation, unknown given status"); | ||
return OperationStatus.FAILED; | ||
} | ||
} | ||
} |
Oops, something went wrong.