Search in sources :

Example 1 with ASDCControllerException

use of org.onap.so.asdc.client.exceptions.ASDCControllerException in project so by onap.

the class ASDCController method initASDC.

/**
 * This method initializes the ASDC Controller and the ASDC Client.
 *
 * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be instantiated or if an init
 *         attempt is done when already initialized
 * @throws ASDCParametersException If there is an issue with the parameters provided
 * @throws IOException In case of issues when trying to load the key file
 */
public void initASDC() throws ASDCControllerException {
    logger.debug("Initialize the ASDC Controller");
    if (!isStopped()) {
        throw new ASDCControllerException("The controller is already initialized, call the closeASDC method first");
    }
    if (asdcConfig != null) {
        asdcConfig.setAsdcControllerName(controllerName);
    }
    if (this.distributionClient == null) {
        distributionClient = DistributionClientFactory.createDistributionClient();
    }
    IDistributionClientResult result = this.distributionClient.init(asdcConfig, asdcNotificationCallBack, asdcStatusCallBack);
    if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
        String endEvent = "ASDC distribution client init failed with reason:" + result.getDistributionMessageResult();
        logger.debug(endEvent);
        this.changeControllerStatus(ASDCControllerStatus.STOPPED);
        throw new ASDCControllerException("Initialization of the ASDC Controller failed with reason: " + result.getDistributionMessageResult());
    }
    result = this.distributionClient.start();
    if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
        String endEvent = "ASDC distribution client start failed with reason:" + result.getDistributionMessageResult();
        logger.debug(endEvent);
        this.changeControllerStatus(ASDCControllerStatus.STOPPED);
        throw new ASDCControllerException("Startup of the ASDC Controller failed with reason: " + result.getDistributionMessageResult());
    }
    this.changeControllerStatus(ASDCControllerStatus.IDLE);
    logger.info(LoggingAnchor.THREE, MessageEnum.ASDC_INIT_ASDC_CLIENT_SUC.toString(), "ASDC", "changeControllerStatus");
}
Also used : IDistributionClientResult(org.onap.sdc.api.results.IDistributionClientResult) ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException)

Example 2 with ASDCControllerException

use of org.onap.so.asdc.client.exceptions.ASDCControllerException in project so by onap.

the class ASDCControllerSingleton method periodicControllerTask.

@ScheduledLogging
@Scheduled(fixedRate = 50000)
public void periodicControllerTask() throws ScheduledTaskException {
    try {
        final int randomNumber = new SecureRandom().nextInt(Integer.MAX_VALUE);
        asdcController.setControllerName("mso-controller" + randomNumber);
        if (asdcController.isStopped()) {
            logger.info("{} not running will try to initialize it, currrent status: {}", asdcController.getClass().getName(), asdcController.getControllerStatus());
            asdcController.initASDC();
        }
    } catch (final ASDCControllerException controllerException) {
        throw new ScheduledTaskException(ErrorCode.UnknownError, controllerException.getMessage(), controllerException);
    }
}
Also used : ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) SecureRandom(java.security.SecureRandom) ScheduledTaskException(org.onap.logging.filter.base.ScheduledTaskException) Scheduled(org.springframework.scheduling.annotation.Scheduled) ScheduledLogging(org.onap.logging.filter.base.ScheduledLogging)

Example 3 with ASDCControllerException

use of org.onap.so.asdc.client.exceptions.ASDCControllerException in project so by onap.

the class ASDCControllerITTest method setUp.

@Before
public void setUp() {
    distributionId = UUID.randomUUID().toString();
    artifactUuid = UUID.randomUUID().toString();
    logger.info("Using distributionId: {}, artifactUUID: {} for testcase: {}", distributionId, artifactUuid, testName.getMethodName());
    distributionClient = new DistributionClientEmulator();
    distributionClient.setResourcePath("src/test/resources");
    asdcController.setDistributionClient(distributionClient);
    try {
        asdcController.initASDC();
    } catch (ASDCControllerException e) {
        logger.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) DistributionClientEmulator(org.onap.so.asdc.client.test.emulators.DistributionClientEmulator) Before(org.junit.Before)

Aggregations

ASDCControllerException (org.onap.so.asdc.client.exceptions.ASDCControllerException)3 SecureRandom (java.security.SecureRandom)1 Before (org.junit.Before)1 ScheduledLogging (org.onap.logging.filter.base.ScheduledLogging)1 ScheduledTaskException (org.onap.logging.filter.base.ScheduledTaskException)1 IDistributionClientResult (org.onap.sdc.api.results.IDistributionClientResult)1 DistributionClientEmulator (org.onap.so.asdc.client.test.emulators.DistributionClientEmulator)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1