Skip to content

Commit

Permalink
Implementation of #12 and documentation
Browse files Browse the repository at this point in the history
- update documentation about architecture risk and technical debts
  and linked issue here.
- renamed Start/Stop parts to more dedicated names - e.g.
  EnableScheduleJobProcessing
- sending and handling missing events/messages
- added integration test for schedule job processing disable/enable
- renamed former named class SchedulerConfig to
  SchedulingEnabledByConditionConfiguration because no longer name
  conflict with new config in db

On behalf of Daimler TSS GmbH.
  • Loading branch information
de-jcup committed Sep 11, 2019
1 parent 0399101 commit e0ea243
Show file tree
Hide file tree
Showing 31 changed files with 537 additions and 268 deletions.
Expand Up @@ -30,19 +30,21 @@ private AdministrationAPIConstants() {
/**
* Stop scheduling (pause)
*/
public static final String API_SCHEDULER_STOP = API_ADMINISTRATION + "scheduler/stop";
public static final String API_SCHEDULER_DISABLE_JOB_PROCESSING = API_ADMINISTRATION + "scheduler/disable/job-processing";

/**
* Stop scheduling (pause)
*/
public static final String API_SCHEDULER_START = API_ADMINISTRATION + "scheduler/start";
public static final String API_SCHEDULER_ENABLE_JOB_PROCESSING = API_ADMINISTRATION + "scheduler/enable/job-processing";


/**
* Refresh scheduler status
*/
public static final String API_SCHEDULER_STATUS_REFRESH = API_ADMINISTRATION + "scheduler/status/refresh";

public static final String API_SCHEDULER_GET_STATUS = API_ADMINISTRATION + "status";

/**
* show all users wanting to sign up
*/
Expand Down Expand Up @@ -86,4 +88,6 @@ private AdministrationAPIConstants() {
public static final String API_REQUEST_NEW_APITOKEN = API_ANONYMOUS+"refresh/apitoken/{emailAddress}";




}

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,4 +1,4 @@
package com.daimler.sechub.domain.administration.schedule;
package com.daimler.sechub.domain.administration.scheduler;

import java.util.Optional;

Expand All @@ -17,9 +17,9 @@
import com.daimler.sechub.sharedkernel.messaging.SchedulerMessage;

@Component
public class SchedulerMessageHandler implements AsynchronMessageHandler{
public class SchedulerAdministrationMessageHandler implements AsynchronMessageHandler{

private static final Logger LOG = LoggerFactory.getLogger(SchedulerMessageHandler.class);
private static final Logger LOG = LoggerFactory.getLogger(SchedulerAdministrationMessageHandler.class);

@Autowired
StatusEntryRepository repository;
Expand All @@ -33,18 +33,45 @@ public void receiveAsyncMessage(DomainMessage request) {
case SCHEDULER_STATUS_UPDATE :
handleSchedulerStatusChange(request);
break;
case SCHEDULER_JOB_PROCESSING_DISABLED:
handleSchedulerJobProcessingDisabled(request);
break;
case SCHEDULER_JOB_PROCESSING_ENABLED:
handleSchedulerJobProcessingEnabled(request);
break;
default:
throw new IllegalStateException("unhandled message id:"+messageId);
}
}

@IsReceivingAsyncMessage(MessageID.SCHEDULER_JOB_PROCESSING_ENABLED)
private void handleSchedulerJobProcessingEnabled(DomainMessage request) {

}

@IsReceivingAsyncMessage(MessageID.SCHEDULER_JOB_PROCESSING_DISABLED)
private void handleSchedulerJobProcessingDisabled(DomainMessage request) {
updateSchedulerJobProcessingEnabled(false);
}


@IsReceivingAsyncMessage(MessageID.SCHEDULER_STATUS_UPDATE)
private void handleSchedulerStatusChange(DomainMessage request) {
SchedulerMessage status = request.get(MessageDataKeys.SCHEDULER_STATUS_DATA);

updateSchedulerJobProcessingEnabled(status.isEnabled());

updateSchedulerJobInformation(status);

}

private void updateSchedulerJobProcessingEnabled(boolean processingEnabled) {
StatusEntry enabled = fetchOrCreateEntry(SchedulerStatusEntryKeys.SCHEDULER_ENABLED);
enabled.setValue(Boolean.toString(status.isEnabled()));
enabled.setValue(Boolean.toString(processingEnabled));
repository.save(enabled);
}

private void updateSchedulerJobInformation(SchedulerMessage status) {
StatusEntry jobsAll= fetchOrCreateEntry(SchedulerStatusEntryKeys.SCHEDULER_JOBS_ALL);
jobsAll.setValue(Integer.toString(status.getAmountOfAllJobs()));

Expand All @@ -55,11 +82,9 @@ private void handleSchedulerStatusChange(DomainMessage request) {
jobsWaiting.setValue(Integer.toString(status.getAmountOfWaitingJobs()));

/* persist */
repository.save(enabled);
repository.save(jobsAll);
repository.save(jobsRunning);
repository.save(jobsWaiting);

}

private StatusEntry fetchOrCreateEntry(SchedulerStatusEntryKeys key) {
Expand Down
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
package com.daimler.sechub.domain.administration.scheduler;

import javax.annotation.security.RolesAllowed;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.daimler.sechub.domain.administration.AdministrationAPIConstants;
import com.daimler.sechub.sharedkernel.RoleConstants;
import com.daimler.sechub.sharedkernel.Step;
import com.daimler.sechub.sharedkernel.usecases.admin.schedule.UseCaseAdministratorDisablesSchedulerJobProcessing;
import com.daimler.sechub.sharedkernel.usecases.admin.schedule.UseCaseAdministratorEnablesSchedulerJobProcessing;

/**
* The rest api for user administration done by a super admin.
*
* @author Albert Tregnaghi
*
*/
@RestController
@EnableAutoConfiguration
@RolesAllowed(RoleConstants.ROLE_SUPERADMIN)
public class SchedulerAdministrationRestController {

@Autowired
SwitchSchedulerJobProcessingService switchJobProcessingService;

@Autowired
TriggerSchedulerStatusRefreshService triggerRefreshService;

/* @formatter:off */
@UseCaseAdministratorEnablesSchedulerJobProcessing(@Step(number=1,name="Rest call",description="Administrator wants to start (unpause) scheduler job processing",needsRestDoc=true))
@RequestMapping(path = AdministrationAPIConstants.API_SCHEDULER_ENABLE_JOB_PROCESSING, method = RequestMethod.POST, produces= {MediaType.APPLICATION_JSON_UTF8_VALUE,MediaType.APPLICATION_JSON_VALUE})
@ResponseStatus(HttpStatus.OK)
public void enableJobProcessing() {
/* @formatter:on */
switchJobProcessingService.enableJobProcessing();
}

/* @formatter:off */
@UseCaseAdministratorDisablesSchedulerJobProcessing(@Step(number=1,name="Rest call",description="Administrator wants to stop (pause) scheduler job processing",needsRestDoc=true))
@RequestMapping(path = AdministrationAPIConstants.API_SCHEDULER_DISABLE_JOB_PROCESSING, method = RequestMethod.POST, produces= {MediaType.APPLICATION_JSON_UTF8_VALUE,MediaType.APPLICATION_JSON_VALUE})
@ResponseStatus(HttpStatus.OK)
public void disableJobProcessing() {
/* @formatter:on */
switchJobProcessingService.disableJobProcessing();
}


}
@@ -1,4 +1,4 @@
package com.daimler.sechub.domain.administration.schedule;
package com.daimler.sechub.domain.administration.scheduler;

import com.daimler.sechub.domain.administration.status.StatusEntryKey;

Expand Down
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
package com.daimler.sechub.domain.administration.scheduler;

import javax.annotation.security.RolesAllowed;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daimler.sechub.sharedkernel.RoleConstants;
import com.daimler.sechub.sharedkernel.Step;
import com.daimler.sechub.sharedkernel.messaging.DomainMessage;
import com.daimler.sechub.sharedkernel.messaging.DomainMessageFactory;
import com.daimler.sechub.sharedkernel.messaging.DomainMessageService;
import com.daimler.sechub.sharedkernel.messaging.IsSendingAsyncMessage;
import com.daimler.sechub.sharedkernel.messaging.MessageID;
import com.daimler.sechub.sharedkernel.usecases.admin.schedule.UseCaseAdministratorEnablesSchedulerJobProcessing;
import com.daimler.sechub.sharedkernel.usecases.admin.schedule.UseCaseAdministratorDisablesSchedulerJobProcessing;

@Service
@RolesAllowed(RoleConstants.ROLE_SUPERADMIN)
public class SwitchSchedulerJobProcessingService {

@Autowired
DomainMessageService eventBusService;

/* @formatter:off */
@UseCaseAdministratorDisablesSchedulerJobProcessing(@Step(number=2,name="Service call",description="Sends request to scheduler domain to disable scheduler job processing"))
public void disableJobProcessing() {
/* @formatter:on */
sendDisableSchedulerJobProcessingMessage();
}

/* @formatter:off */
@UseCaseAdministratorEnablesSchedulerJobProcessing(@Step(number=2,name="Service call",description="Sends request to scheduler domain to enable scheduler job processing"))
public void enableJobProcessing() {
/* @formatter:on */
sendEnableSchedulerJobProcessingMessage();
}

@IsSendingAsyncMessage(MessageID.REQUEST_SCHEDULER_ENABLE_JOB_PROCESSING)
private void sendEnableSchedulerJobProcessingMessage() {
DomainMessage request = DomainMessageFactory.createEmptyRequest(MessageID.REQUEST_SCHEDULER_ENABLE_JOB_PROCESSING);
eventBusService.sendAsynchron(request);
}

@IsSendingAsyncMessage(MessageID.REQUEST_SCHEDULER_DISABLE_JOB_PROCESSING)
private void sendDisableSchedulerJobProcessingMessage() {
DomainMessage request = DomainMessageFactory.createEmptyRequest(MessageID.REQUEST_SCHEDULER_DISABLE_JOB_PROCESSING);
eventBusService.sendAsynchron(request);
}

}

0 comments on commit e0ea243

Please sign in to comment.