Reduce entity changes as part of DDI/DMF update feedback (#478)

* TargetUpdateQuery and poll event only for polls and not feedback.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix test.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove unused field

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-04-12 21:41:32 +02:00
committed by GitHub
parent 32fe53708e
commit 2ac2eac997
10 changed files with 23 additions and 112 deletions

View File

@@ -22,6 +22,7 @@ import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException; import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.SoftwareModuleNotAssignedToTargetException; import org.eclipse.hawkbit.repository.exception.SoftwareModuleNotAssignedToTargetException;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Action.Status;
@@ -30,8 +31,6 @@ import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder; import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper; import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper;
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
import org.eclipse.hawkbit.util.IpUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -62,9 +61,6 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
@Autowired @Autowired
private ControllerManagement controllerManagement; private ControllerManagement controllerManagement;
@Autowired
private HawkbitSecurityProperties securityProperties;
@Autowired @Autowired
private RequestResponseContextHolder requestResponseContextHolder; private RequestResponseContextHolder requestResponseContextHolder;
@@ -134,10 +130,10 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
private ActionStatus checkAndReportDownloadByTarget(final HttpServletRequest request, final String targetid, private ActionStatus checkAndReportDownloadByTarget(final HttpServletRequest request, final String controllerId,
final Artifact artifact) { final Artifact artifact) {
final Target target = controllerManagement.updateLastTargetQuery(targetid, final Target target = controllerManagement.findByControllerId(controllerId)
IpUtil.getClientIpFromRequest(request, securityProperties)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
final Action action = controllerManagement final Action action = controllerManagement
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), .getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(),

View File

@@ -111,8 +111,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
@PathVariable("softwareModuleId") final Long softwareModuleId) { @PathVariable("softwareModuleId") final Long softwareModuleId) {
LOG.debug("getSoftwareModulesArtifacts({})", controllerId); LOG.debug("getSoftwareModulesArtifacts({})", controllerId);
final Target target = controllerManagement.updateLastTargetQuery(controllerId, IpUtil final Target target = controllerManagement.findByControllerId(controllerId)
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(softwareModuleId) final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(softwareModuleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
@@ -142,8 +142,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
@PathVariable("fileName") final String fileName) { @PathVariable("fileName") final String fileName) {
ResponseEntity<InputStream> result; ResponseEntity<InputStream> result;
final Target target = controllerManagement.updateLastTargetQuery(controllerId, IpUtil final Target target = controllerManagement.findByControllerId(controllerId)
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId) final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
@@ -205,8 +205,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
@PathVariable("controllerId") final String controllerId, @PathVariable("controllerId") final String controllerId,
@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("fileName") final String fileName) { @PathVariable("fileName") final String fileName) {
controllerManagement.updateLastTargetQuery(controllerId, IpUtil controllerManagement.findByControllerId(controllerId)
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId) final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
@@ -234,8 +234,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
@RequestParam(value = "c", required = false, defaultValue = "-1") final int resource) { @RequestParam(value = "c", required = false, defaultValue = "-1") final int resource) {
LOG.debug("getControllerBasedeploymentAction({},{})", controllerId, resource); LOG.debug("getControllerBasedeploymentAction({},{})", controllerId, resource);
final Target target = controllerManagement.updateLastTargetQuery(controllerId, IpUtil final Target target = controllerManagement.findByControllerId(controllerId)
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
final Action action = findActionWithExceptionIfNotFound(actionId); final Action action = findActionWithExceptionIfNotFound(actionId);
if (!action.getTarget().getId().equals(target.getId())) { if (!action.getTarget().getId().equals(target.getId())) {
@@ -271,8 +271,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
@PathVariable("actionId") @NotEmpty final Long actionId) { @PathVariable("actionId") @NotEmpty final Long actionId) {
LOG.debug("provideBasedeploymentActionFeedback for target [{},{}]: {}", controllerId, actionId, feedback); LOG.debug("provideBasedeploymentActionFeedback for target [{},{}]: {}", controllerId, actionId, feedback);
final Target target = controllerManagement.updateLastTargetQuery(controllerId, IpUtil final Target target = controllerManagement.findByControllerId(controllerId)
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
if (!actionId.equals(feedback.getId())) { if (!actionId.equals(feedback.getId())) {
LOG.warn( LOG.warn(
@@ -361,9 +361,6 @@ public class DdiRootController implements DdiRootControllerRestApi {
@Override @Override
public ResponseEntity<Void> putConfigData(@Valid @RequestBody final DdiConfigData configData, public ResponseEntity<Void> putConfigData(@Valid @RequestBody final DdiConfigData configData,
@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId) { @PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId) {
controllerManagement.updateLastTargetQuery(controllerId, IpUtil
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties));
controllerManagement.updateControllerAttributes(controllerId, configData.getData()); controllerManagement.updateControllerAttributes(controllerId, configData.getData());
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
@@ -375,8 +372,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
@PathVariable("actionId") @NotEmpty final Long actionId) { @PathVariable("actionId") @NotEmpty final Long actionId) {
LOG.debug("getControllerCancelAction({})", controllerId); LOG.debug("getControllerCancelAction({})", controllerId);
final Target target = controllerManagement.updateLastTargetQuery(controllerId, IpUtil final Target target = controllerManagement.findByControllerId(controllerId)
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
final Action action = findActionWithExceptionIfNotFound(actionId); final Action action = findActionWithExceptionIfNotFound(actionId);
if (!action.getTarget().getId().equals(target.getId())) { if (!action.getTarget().getId().equals(target.getId())) {
@@ -406,8 +403,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
@PathVariable("actionId") @NotEmpty final Long actionId) { @PathVariable("actionId") @NotEmpty final Long actionId) {
LOG.debug("provideCancelActionFeedback for target [{}]: {}", controllerId, feedback); LOG.debug("provideCancelActionFeedback for target [{}]: {}", controllerId, feedback);
final Target target = controllerManagement.updateLastTargetQuery(controllerId, IpUtil final Target target = controllerManagement.findByControllerId(controllerId)
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
if (!actionId.equals(feedback.getId())) { if (!actionId.equals(feedback.getId())) {
LOG.warn( LOG.warn(

View File

@@ -166,8 +166,6 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
.andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction.getId())))); .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction.getId()))));
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis()); .getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
// controller confirmed cancelled action, should not be active anymore // controller confirmed cancelled action, should not be active anymore
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
@@ -244,50 +242,38 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
long current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
.content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "proceeding")) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "proceeding"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
.content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "resumed")) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "resumed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
.content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "scheduled")) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "scheduled"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
// cancellation canceled -> should remove the action from active // cancellation canceled -> should remove the action from active
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
.content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "canceled")) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "canceled"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
@@ -296,26 +282,20 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
// with finished or // with finished or
// error // error
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
.content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "rejected")) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "rejected"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
// update closed -> should remove the action from active // update closed -> should remove the action from active
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/deploymentBase/" mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/deploymentBase/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
.content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "closed")) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "closed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(0);
} }

View File

@@ -93,32 +93,16 @@ public class DdiConfigDataTest extends AbstractDDiApiIntegrationTest {
final Map<String, String> attributes = new HashMap<>(); final Map<String, String> attributes = new HashMap<>();
attributes.put("dsafsdf", "sdsds"); attributes.put("dsafsdf", "sdsds");
long current = System.currentTimeMillis();
mvc.perform(put("/{tenant}/controller/v1/4717/configData", tenantAware.getCurrentTenant()) mvc.perform(put("/{tenant}/controller/v1/4717/configData", tenantAware.getCurrentTenant())
.content(JsonBuilder.configData("", attributes, "closed")).contentType(MediaType.APPLICATION_JSON)) .content(JsonBuilder.configData("", attributes, "closed")).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
Thread.sleep(1); // is required: otherwise processing the next line is
// often too fast and
// the following assert will fail
assertThat(targetManagement.findTargetByControllerID("4717").get().getLastTargetQuery())
.isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(targetManagement.findTargetByControllerID("4717").get().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
assertThat(targetManagement.getControllerAttributes("4717")).isEqualTo(attributes); assertThat(targetManagement.getControllerAttributes("4717")).isEqualTo(attributes);
// update // update
attributes.put("sdsds", "123412"); attributes.put("sdsds", "123412");
current = System.currentTimeMillis();
mvc.perform(put("/{tenant}/controller/v1/4717/configData", tenantAware.getCurrentTenant()) mvc.perform(put("/{tenant}/controller/v1/4717/configData", tenantAware.getCurrentTenant())
.content(JsonBuilder.configData("", attributes, "closed")).contentType(MediaType.APPLICATION_JSON)) .content(JsonBuilder.configData("", attributes, "closed")).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
Thread.sleep(1); // is required: otherwise processing the next line is
// often too fast and
// the following assert will fail
assertThat(targetManagement.findTargetByControllerID("4717").get().getLastTargetQuery())
.isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(targetManagement.findTargetByControllerID("4717").get().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
assertThat(targetManagement.getControllerAttributes("4717")).isEqualTo(attributes); assertThat(targetManagement.getControllerAttributes("4717")).isEqualTo(attributes);
} }

View File

@@ -213,8 +213,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
contains(ds.findFirstModuleByType(appType).get().getVersion()))) contains(ds.findFirstModuleByType(appType).get().getVersion())))
.andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name", .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name",
contains(ds.findFirstModuleByType(appType).get().getName()))); contains(ds.findFirstModuleByType(appType).get().getName())));
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
// Retrieved is reported // Retrieved is reported
final Iterable<ActionStatus> actionStatusMessages = deploymentManagement final Iterable<ActionStatus> actionStatusMessages = deploymentManagement
@@ -301,7 +299,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
// Run test // Run test
long current = System.currentTimeMillis(); final long current = System.currentTimeMillis();
mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
@@ -314,8 +312,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
.isLessThanOrEqualTo(System.currentTimeMillis()); .isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
current = System.currentTimeMillis();
final DistributionSet findDistributionSetByAction = distributionSetManagement final DistributionSet findDistributionSetByAction = distributionSetManagement
.findDistributionSetByAction(action.getId()).get(); .findDistributionSetByAction(action.getId()).get();
@@ -371,8 +367,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
contains(ds.findFirstModuleByType(appType).get().getVersion()))) contains(ds.findFirstModuleByType(appType).get().getVersion())))
.andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name", .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name",
contains(ds.findFirstModuleByType(appType).get().getName()))); contains(ds.findFirstModuleByType(appType).get().getName())));
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
// Retrieved is reported // Retrieved is reported
final List<ActionStatus> actionStatusMessages = deploymentManagement final List<ActionStatus> actionStatusMessages = deploymentManagement
@@ -488,8 +482,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
contains(ds.findFirstModuleByType(appType).get().getVersion()))) contains(ds.findFirstModuleByType(appType).get().getVersion())))
.andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name", .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name",
contains(ds.findFirstModuleByType(appType).get().getName()))); contains(ds.findFirstModuleByType(appType).get().getName())));
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
// Retrieved is reported // Retrieved is reported
final Iterable<ActionStatus> actionStatusMessages = deploymentManagement final Iterable<ActionStatus> actionStatusMessages = deploymentManagement
@@ -595,15 +587,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
// action1 done // action1 done
long current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action1.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action1.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action1.getId().toString(), "closed")) .content(JsonBuilder.deploymentActionFeedback(action1.getId().toString(), "closed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(2); assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(2);
assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3);
@@ -615,15 +604,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(actionStatusMessages.iterator().next().getStatus()).isEqualTo(Status.FINISHED); assertThat(actionStatusMessages.iterator().next().getStatus()).isEqualTo(Status.FINISHED);
// action2 done // action2 done
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action2.getId().toString(), "closed")) .content(JsonBuilder.deploymentActionFeedback(action2.getId().toString(), "closed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
@@ -635,15 +621,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(actionStatusMessages).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); assertThat(actionStatusMessages).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED));
// action3 done // action3 done
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action3.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action3.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action3.getId().toString(), "closed")) .content(JsonBuilder.deploymentActionFeedback(action3.getId().toString(), "closed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0);
assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3);
@@ -670,7 +653,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds.getId()).getContent() final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds.getId()).getContent()
.get(0); .get(0);
long current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed", "failure", .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed", "failure",
@@ -678,8 +660,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
Target myT = targetManagement.findTargetByControllerID("4712").get(); Target myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.ERROR); .isEqualTo(TargetUpdateStatus.ERROR);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
@@ -699,7 +679,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get(); ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
assignDistributionSet(ds, Lists.newArrayList(targetManagement.findTargetByControllerID("4712").get())); assignDistributionSet(ds, Lists.newArrayList(targetManagement.findTargetByControllerID("4712").get()));
final Action action2 = deploymentManagement.findActiveActionsByTarget(myT.getControllerId()).get(0); final Action action2 = deploymentManagement.findActiveActionsByTarget(myT.getControllerId()).get(0);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
@@ -708,8 +687,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
.hasSize(0); .hasSize(0);
@@ -748,9 +725,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1); assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1);
// Now valid Feedback // Now valid Feedback
long current = System.currentTimeMillis();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
@@ -760,7 +734,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
} }
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
.hasSize(1); .hasSize(1);
@@ -773,14 +746,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5, assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5,
new ActionStatusCondition(Status.RUNNING)); new ActionStatusCondition(Status.RUNNING));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "scheduled")) .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "scheduled"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
.hasSize(1); .hasSize(1);
@@ -793,14 +764,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5, assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5,
new ActionStatusCondition(Status.RUNNING)); new ActionStatusCondition(Status.RUNNING));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "resumed")) .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "resumed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
.hasSize(1); .hasSize(1);
@@ -813,14 +782,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6, assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6,
new ActionStatusCondition(Status.RUNNING)); new ActionStatusCondition(Status.RUNNING));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "canceled")) .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "canceled"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
@@ -836,14 +803,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1,
new ActionStatusCondition(Status.CANCELED)); new ActionStatusCondition(Status.CANCELED));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "rejected")) .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "rejected"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9);
@@ -854,14 +819,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1,
new ActionStatusCondition(Status.CANCELED)); new ActionStatusCondition(Status.CANCELED));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
tenantAware.getCurrentTenant()) tenantAware.getCurrentTenant())
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed")) .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
myT = targetManagement.findTargetByControllerID("4712").get(); myT = targetManagement.findTargetByControllerID("4712").get();
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR))

View File

@@ -178,7 +178,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
@Test @Test
@Description("Ensures that etag check results in not modified response if provided etag by client is identical to entity in repository.") @Description("Ensures that etag check results in not modified response if provided etag by client is identical to entity in repository.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 7), @Expect(type = TargetPollEvent.class, count = 6),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 2),
@Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = ActionUpdatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetCreatedEvent.class, count = 2),
@@ -323,7 +323,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
@Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 3), @Expect(type = TargetUpdatedEvent.class, count = 2),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3) }) @Expect(type = SoftwareModuleCreatedEvent.class, count = 3) })
public void tryToFinishAnUpdateProcessAfterItHasBeenFinished() throws Exception { public void tryToFinishAnUpdateProcessAfterItHasBeenFinished() throws Exception {
final DistributionSet ds = testdataFactory.createDistributionSet(""); final DistributionSet ds = testdataFactory.createDistributionSet("");

View File

@@ -245,8 +245,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
+ convertCorrelationId(message)); + convertCorrelationId(message));
} }
updateLastPollTime(action.getTarget());
final Status status = mapStatus(message, actionUpdateStatus, action); final Status status = mapStatus(message, actionUpdateStatus, action);
final ActionStatusCreate actionStatus = entityFactory.actionStatus().create(action.getId()).status(status) final ActionStatusCreate actionStatus = entityFactory.actionStatus().create(action.getId()).status(status)
.messages(messages); .messages(messages);
@@ -302,10 +300,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
} }
private void updateLastPollTime(final Target target) {
controllerManagement.updateLastTargetQuery(target.getControllerId(), null);
}
private static String convertCorrelationId(final Message message) { private static String convertCorrelationId(final Message message) {
return new String(message.getMessageProperties().getCorrelationId(), StandardCharsets.UTF_8); return new String(message.getMessageProperties().getCorrelationId(), StandardCharsets.UTF_8);
} }

View File

@@ -58,7 +58,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Captor; import org.mockito.Captor;
import org.mockito.Matchers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.amqp.AmqpRejectAndDontRequeueException; import org.springframework.amqp.AmqpRejectAndDontRequeueException;
@@ -418,9 +417,6 @@ public class AmqpMessageHandlerServiceTest {
// test // test
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost"); amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
// verify
verify(controllerManagementMock).updateLastTargetQuery(any(String.class), Matchers.isNull(URI.class));
final ArgumentCaptor<String> tenantCaptor = ArgumentCaptor.forClass(String.class); final ArgumentCaptor<String> tenantCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<Target> targetCaptor = ArgumentCaptor.forClass(Target.class); final ArgumentCaptor<Target> targetCaptor = ArgumentCaptor.forClass(Target.class);
final ArgumentCaptor<Long> actionIdCaptor = ArgumentCaptor.forClass(Long.class); final ArgumentCaptor<Long> actionIdCaptor = ArgumentCaptor.forClass(Long.class);

View File

@@ -401,7 +401,6 @@ public class JpaControllerManagement implements ControllerManagement {
String.valueOf(securityProperties.getDos().getMaxAttributeEntriesPerTarget())); String.valueOf(securityProperties.getDos().getMaxAttributeEntriesPerTarget()));
} }
target.setLastTargetQuery(System.currentTimeMillis());
target.setRequestControllerAttributes(false); target.setRequestControllerAttributes(false);
return targetRepository.save(target); return targetRepository.save(target);

View File

@@ -49,12 +49,14 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
.name("targetName123").description("targetDesc123")); .name("targetName123").description("targetDesc123"));
attributes.put("revision", "1.1"); attributes.put("revision", "1.1");
target = controllerManagement.updateControllerAttributes(target.getControllerId(), attributes); target = controllerManagement.updateControllerAttributes(target.getControllerId(), attributes);
target = controllerManagement.updateLastTargetQuery(target.getControllerId(), null);
target2 = targetManagement target2 = targetManagement
.createTarget(entityFactory.target().create().controllerId("targetId1234").description("targetId1234")); .createTarget(entityFactory.target().create().controllerId("targetId1234").description("targetId1234"));
attributes.put("revision", "1.2"); attributes.put("revision", "1.2");
Thread.sleep(1); Thread.sleep(1);
target2 = controllerManagement.updateControllerAttributes(target2.getControllerId(), attributes); target2 = controllerManagement.updateControllerAttributes(target2.getControllerId(), attributes);
target2 = controllerManagement.updateLastTargetQuery(target2.getControllerId(), null);
testdataFactory.createTarget("targetId1235"); testdataFactory.createTarget("targetId1235");
testdataFactory.createTarget("targetId1236"); testdataFactory.createTarget("targetId1236");