Remove TargetInfo entity (#453)
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -47,17 +47,17 @@ public enum TargetFields implements FieldNameProvider {
|
||||
/**
|
||||
* The updateStatus field.
|
||||
*/
|
||||
UPDATESTATUS("targetInfo.updateStatus"),
|
||||
UPDATESTATUS("updateStatus"),
|
||||
|
||||
/**
|
||||
* The ip-address field.
|
||||
*/
|
||||
IPADDRESS("targetInfo.address"),
|
||||
IPADDRESS("address"),
|
||||
|
||||
/**
|
||||
* The attribute map of target info.
|
||||
*/
|
||||
ATTRIBUTE("targetInfo.controllerAttributes", true),
|
||||
ATTRIBUTE("controllerAttributes", true),
|
||||
|
||||
/**
|
||||
* distribution sets which is assigned to the target.
|
||||
@@ -67,7 +67,7 @@ public enum TargetFields implements FieldNameProvider {
|
||||
/**
|
||||
* distribution sets which is installed on the target.
|
||||
*/
|
||||
INSTALLEDDS("targetInfo.installedDistributionSet", "name", "version"),
|
||||
INSTALLEDDS("installedDistributionSet", "name", "version"),
|
||||
|
||||
/**
|
||||
* The tags field.
|
||||
@@ -75,9 +75,9 @@ public enum TargetFields implements FieldNameProvider {
|
||||
TAG("tags.name"),
|
||||
|
||||
/**
|
||||
* Last time the target or DMF client polled.
|
||||
* Last time the DDI or DMF client polled.
|
||||
*/
|
||||
LASTCONTROLLERREQUESTAT("targetInfo.lastTargetQuery");
|
||||
LASTCONTROLLERREQUESTAT("lastTargetQuery");
|
||||
|
||||
private final String fieldName;
|
||||
private List<String> subEntityAttribues;
|
||||
|
||||
@@ -124,7 +124,7 @@ public final class DataConversionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
if (target.getTargetInfo().isRequestControllerAttributes()) {
|
||||
if (target.isRequestControllerAttributes()) {
|
||||
result.add(ControllerLinkBuilder
|
||||
.linkTo(ControllerLinkBuilder.methodOn(DdiRootController.class, tenantAware.getCurrentTenant())
|
||||
.putConfigData(null, tenantAware.getCurrentTenant(), target.getControllerId()))
|
||||
|
||||
@@ -88,12 +88,12 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
// check database after test
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(TestdataFactory.DEFAULT_CONTROLLER_ID).get())
|
||||
.isEqualTo(ds);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(TestdataFactory.DEFAULT_CONTROLLER_ID).get())
|
||||
.isEqualTo(ds);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getAssignedDistributionSet().getId()).isEqualTo(ds.getId());
|
||||
assertThat(targetManagement.findTargetByControllerIDWithDetails(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getInstalledDistributionSet().getId()).isEqualTo(ds.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getInstallationDate()).isGreaterThanOrEqualTo(current);
|
||||
.getInstallationDate()).isGreaterThanOrEqualTo(current);
|
||||
|
||||
}
|
||||
|
||||
@@ -119,9 +119,9 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
|
||||
// Retrieved is reported
|
||||
|
||||
@@ -151,13 +151,13 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
|
||||
current = System.currentTimeMillis();
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
mvc.perform(get("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
|
||||
+ cancelAction.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -165,9 +165,9 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction.getId()))))
|
||||
.andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction.getId()))));
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
|
||||
// controller confirmed cancelled action, should not be active anymore
|
||||
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
|
||||
@@ -251,7 +251,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3);
|
||||
@@ -263,7 +263,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4);
|
||||
|
||||
@@ -274,7 +274,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
|
||||
|
||||
@@ -287,7 +287,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
|
||||
|
||||
@@ -303,7 +303,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
|
||||
|
||||
@@ -315,7 +315,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(0);
|
||||
}
|
||||
@@ -403,8 +403,8 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9);
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getAssignedDistributionSet()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(TestdataFactory.DEFAULT_CONTROLLER_ID).get())
|
||||
.isEqualTo(ds3);
|
||||
mvc.perform(get("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/deploymentBase/"
|
||||
+ updateAction3.getId(), tenantAware.getCurrentTenant())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
@@ -418,8 +418,8 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
// action is in cancelling state
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
|
||||
assertThat(deploymentManagement.countActionsByTarget(savedTarget.getControllerId())).isEqualTo(3);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getAssignedDistributionSet()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(TestdataFactory.DEFAULT_CONTROLLER_ID).get())
|
||||
.isEqualTo(ds3);
|
||||
|
||||
mvc.perform(get("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
|
||||
+ cancelAction3.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
@@ -29,6 +29,8 @@ import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@@ -58,19 +60,20 @@ public class DdiConfigDataTest extends AbstractDDiApiIntegrationTest {
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
|
||||
savedTarget.getTargetInfo().getControllerAttributes().put("dsafsdf", "sdsds");
|
||||
final Map<String, String> attributes = Maps.newHashMapWithExpectedSize(1);
|
||||
attributes.put("dsafsdf", "sdsds");
|
||||
|
||||
final Target updateControllerAttributes = controllerManagement.updateControllerAttributes(
|
||||
savedTarget.getControllerId(), savedTarget.getTargetInfo().getControllerAttributes());
|
||||
final Target updateControllerAttributes = controllerManagement
|
||||
.updateControllerAttributes(savedTarget.getControllerId(), attributes);
|
||||
// request controller attributes need to be false because we don't want
|
||||
// to request the
|
||||
// controller attributes again
|
||||
assertThat(updateControllerAttributes.getTargetInfo().isRequestControllerAttributes()).isFalse();
|
||||
assertThat(updateControllerAttributes.isRequestControllerAttributes()).isFalse();
|
||||
|
||||
mvc.perform(
|
||||
get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant()).accept(APPLICATION_JSON_HAL_UTF))
|
||||
@@ -97,12 +100,11 @@ public class DdiConfigDataTest extends AbstractDDiApiIntegrationTest {
|
||||
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().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4717").get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID("4717").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4717").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.findTargetByControllerIDWithDetails("4717").get().getTargetInfo()
|
||||
.getControllerAttributes()).isEqualTo(attributes);
|
||||
assertThat(targetManagement.getControllerAttributes("4717")).isEqualTo(attributes);
|
||||
|
||||
// update
|
||||
attributes.put("sdsds", "123412");
|
||||
@@ -113,12 +115,11 @@ public class DdiConfigDataTest extends AbstractDDiApiIntegrationTest {
|
||||
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().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4717").get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID("4717").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4717").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.findTargetByControllerIDWithDetails("4717").get().getTargetInfo()
|
||||
.getControllerAttributes()).isEqualTo(attributes);
|
||||
assertThat(targetManagement.getControllerAttributes("4717")).isEqualTo(attributes);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -146,9 +146,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")))
|
||||
.andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/"
|
||||
+ tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId())));
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
|
||||
|
||||
@@ -213,7 +213,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
contains(ds.findFirstModuleByType(appType).get().getVersion())))
|
||||
.andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name",
|
||||
contains(ds.findFirstModuleByType(appType).get().getName())));
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
|
||||
// Retrieved is reported
|
||||
@@ -308,9 +308,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")))
|
||||
.andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/"
|
||||
+ tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId())));
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
|
||||
|
||||
@@ -371,7 +371,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
contains(ds.findFirstModuleByType(appType).get().getVersion())))
|
||||
.andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name",
|
||||
contains(ds.findFirstModuleByType(appType).get().getName())));
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
|
||||
// Retrieved is reported
|
||||
@@ -424,9 +424,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")))
|
||||
.andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/"
|
||||
+ tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId())));
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
|
||||
|
||||
@@ -488,7 +488,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
contains(ds.findFirstModuleByType(appType).get().getVersion())))
|
||||
.andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name",
|
||||
contains(ds.findFirstModuleByType(appType).get().getName())));
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
|
||||
// Retrieved is reported
|
||||
@@ -586,10 +586,10 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.findActionWithDetails(assignDistributionSet(ds3.getId(), "4712").getActions().get(0)).get();
|
||||
|
||||
Target myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(3);
|
||||
assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3);
|
||||
assertThat(myT.getTargetInfo().getInstalledDistributionSet()).isNull();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId())).isNotPresent();
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.UNKNOWN))
|
||||
.hasSize(2);
|
||||
|
||||
@@ -601,13 +601,13 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.content(JsonBuilder.deploymentActionFeedback(action1.getId().toString(), "closed"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
myT = targetManagement.findTargetByControllerIDWithDetails("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(2);
|
||||
assertThat(myT.getTargetInfo().getInstalledDistributionSet().getId()).isEqualTo(ds1.getId());
|
||||
assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId()).get()).isEqualTo(ds1);
|
||||
|
||||
Iterable<ActionStatus> actionStatusMessages = deploymentManagement
|
||||
.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")).getContent();
|
||||
@@ -621,14 +621,14 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.content(JsonBuilder.deploymentActionFeedback(action2.getId().toString(), "closed"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
myT = targetManagement.findTargetByControllerIDWithDetails("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
|
||||
assertThat(myT.getTargetInfo().getInstalledDistributionSet().getId()).isEqualTo(ds2.getId());
|
||||
assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId()).get()).isEqualTo(ds2);
|
||||
actionStatusMessages = deploymentManagement.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id"))
|
||||
.getContent();
|
||||
assertThat(actionStatusMessages).hasSize(5);
|
||||
@@ -642,12 +642,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0);
|
||||
assertThat(myT.getTargetInfo().getInstalledDistributionSet()).isEqualTo(ds3);
|
||||
assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3);
|
||||
actionStatusMessages = deploymentManagement.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id"))
|
||||
.getContent();
|
||||
assertThat(actionStatusMessages).hasSize(6);
|
||||
@@ -664,7 +664,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
assignDistributionSet(ds, toAssign);
|
||||
final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds.getId()).getContent()
|
||||
@@ -678,9 +678,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Target myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.ERROR);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
|
||||
.hasSize(0);
|
||||
@@ -708,9 +708,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(myT.getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
|
||||
.hasSize(0);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR))
|
||||
@@ -737,13 +737,13 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
final List<Target> toAssign = Lists.newArrayList(savedTarget);
|
||||
|
||||
Target myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
assignDistributionSet(ds, toAssign);
|
||||
final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds.getId()).getContent()
|
||||
.get(0);
|
||||
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), pageReq)).hasSize(0);
|
||||
assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1);
|
||||
|
||||
@@ -760,8 +760,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
}
|
||||
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
|
||||
.hasSize(1);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR))
|
||||
@@ -780,8 +780,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
|
||||
.hasSize(1);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR))
|
||||
@@ -800,8 +800,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
|
||||
.hasSize(1);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR))
|
||||
@@ -820,8 +820,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
|
||||
.hasSize(1);
|
||||
@@ -843,8 +843,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
|
||||
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9);
|
||||
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6,
|
||||
@@ -861,8 +861,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
myT = targetManagement.findTargetByControllerID("4712").get();
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(myT.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0);
|
||||
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR))
|
||||
.hasSize(0);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
|
||||
// make a poll, audit information should not be changed, run as
|
||||
// controller principal!
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUser("controller", CONTROLLER_ROLE_ANONYMOUS), () -> {
|
||||
securityRule.runAs(WithSpringAuthorityRule.withController("controller", CONTROLLER_ROLE_ANONYMOUS), () -> {
|
||||
mvc.perform(get("/{tenant}/controller/v1/" + knownTargetControllerId, tenantAware.getCurrentTenant()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
return null;
|
||||
@@ -118,7 +118,6 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
assertThat(targetVerify.getCreatedAt()).isEqualTo(findTargetByControllerID.getCreatedAt());
|
||||
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(findTargetByControllerID.getLastModifiedBy());
|
||||
assertThat(targetVerify.getLastModifiedAt()).isEqualTo(findTargetByControllerID.getLastModifiedAt());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,10 +137,10 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
mvc.perform(get("/default-tenant/controller/v1/4711")).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")));
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.REGISTERED);
|
||||
|
||||
// not allowed methods
|
||||
@@ -254,7 +253,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
public void rootRsPrecommissioned() throws Exception {
|
||||
final Target target = testdataFactory.createTarget("4711");
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
|
||||
final long current = System.currentTimeMillis();
|
||||
@@ -263,12 +262,12 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")));
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getTargetInfo().getLastTargetQuery())
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.REGISTERED);
|
||||
}
|
||||
|
||||
@@ -279,12 +278,23 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
public void rootRsPlugAndPlayIpAddress() throws Exception {
|
||||
// test
|
||||
final String knownControllerId1 = "0815";
|
||||
mvc.perform(get("/{tenant}/controller/v1/{controllerId}", tenantAware.getCurrentTenant(), knownControllerId1))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
final long create = System.currentTimeMillis();
|
||||
|
||||
// make a poll, audit information should be set on plug and play
|
||||
securityRule.runAs(WithSpringAuthorityRule.withController("controller", CONTROLLER_ROLE_ANONYMOUS), () -> {
|
||||
mvc.perform(
|
||||
get("/{tenant}/controller/v1/{controllerId}", tenantAware.getCurrentTenant(), knownControllerId1))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
return null;
|
||||
});
|
||||
|
||||
// verify
|
||||
final Target target = targetManagement.findTargetByControllerID(knownControllerId1).get();
|
||||
assertThat(target.getTargetInfo().getAddress()).isEqualTo(IpUtil.createHttpUri("127.0.0.1"));
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createHttpUri("127.0.0.1"));
|
||||
assertThat(target.getCreatedBy()).isEqualTo("CONTROLLER_PLUG_AND_PLAY");
|
||||
assertThat(target.getCreatedAt()).isGreaterThanOrEqualTo(create);
|
||||
assertThat(target.getLastModifiedBy()).isNull();
|
||||
assertThat(target.getLastModifiedAt()).isNull();
|
||||
|
||||
}
|
||||
|
||||
@@ -302,7 +312,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
|
||||
// verify
|
||||
final Target target = targetManagement.findTargetByControllerID(knownControllerId1).get();
|
||||
assertThat(target.getTargetInfo().getAddress()).isEqualTo(IpUtil.createHttpUri("***"));
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createHttpUri("***"));
|
||||
|
||||
securityProperties.getClients().setTrackRemoteIp(true);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
void sendUpdateMessageToTarget(final String tenant, final Target target, final Long actionId,
|
||||
final Collection<org.eclipse.hawkbit.repository.model.SoftwareModule> modules) {
|
||||
|
||||
final URI targetAdress = target.getTargetInfo().getAddress();
|
||||
final URI targetAdress = target.getAddress();
|
||||
if (!IpUtil.isAmqpUri(targetAdress)) {
|
||||
return;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
}
|
||||
|
||||
sendCancelMessageToTarget(cancelEvent.getTenant(), cancelEvent.getEntity().getControllerId(),
|
||||
cancelEvent.getActionId(), cancelEvent.getEntity().getTargetInfo().getAddress());
|
||||
cancelEvent.getActionId(), cancelEvent.getEntity().getAddress());
|
||||
}
|
||||
|
||||
private boolean isFromSelf(final RemoteApplicationEvent event) {
|
||||
|
||||
@@ -189,7 +189,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
final Action action = actionOptional.get();
|
||||
if (action.isCancelingOrCanceled()) {
|
||||
amqpMessageDispatcherService.sendCancelMessageToTarget(target.getTenant(), target.getControllerId(),
|
||||
action.getId(), target.getTargetInfo().getAddress());
|
||||
action.getId(), target.getAddress());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
private Message getCaptureAdressEvent(final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent) {
|
||||
final Target target = targetManagement
|
||||
.findTargetByControllerID(targetAssignDistributionSetEvent.getControllerId()).get();
|
||||
final Message sendMessage = createArgumentCapture(target.getTargetInfo().getAddress());
|
||||
final Message sendMessage = createArgumentCapture(target.getAddress());
|
||||
return sendMessage;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
.stream().filter(dmfartifact -> dmfartifact.getFilename().equals(dbArtifact.getFilename()))
|
||||
.findAny();
|
||||
|
||||
assertTrue("The artifact should exist in message", found.isPresent());
|
||||
assertThat(found).as("The artifact should exist in message").isPresent();
|
||||
assertThat(found.get().getSize()).isEqualTo(dbArtifact.getSize());
|
||||
assertThat(found.get().getHashes().getMd5()).isEqualTo(dbArtifact.getMd5Hash());
|
||||
assertThat(found.get().getHashes().getSha1()).isEqualTo(dbArtifact.getSha1Hash());
|
||||
@@ -223,7 +223,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
amqpMessageDispatcherService
|
||||
.targetCancelAssignmentToDistributionSet(cancelTargetAssignmentDistributionSetEvent);
|
||||
final Message sendMessage = createArgumentCapture(
|
||||
cancelTargetAssignmentDistributionSetEvent.getEntity().getTargetInfo().getAddress());
|
||||
cancelTargetAssignmentDistributionSetEvent.getEntity().getAddress());
|
||||
assertCancelMessage(sendMessage);
|
||||
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -472,7 +471,6 @@ public class AmqpMessageHandlerServiceTest {
|
||||
// Mock
|
||||
final Action actionMock = mock(Action.class);
|
||||
final Target targetMock = mock(Target.class);
|
||||
final TargetInfo targetInfoMock = mock(TargetInfo.class);
|
||||
final DistributionSet distributionSetMock = mock(DistributionSet.class);
|
||||
|
||||
when(distributionSetMock.getId()).thenReturn(1L);
|
||||
@@ -483,8 +481,7 @@ public class AmqpMessageHandlerServiceTest {
|
||||
when(actionMock.getTarget()).thenReturn(targetMock);
|
||||
when(targetMock.getControllerId()).thenReturn("target1");
|
||||
when(targetMock.getSecurityToken()).thenReturn("securityToken");
|
||||
when(targetMock.getTargetInfo()).thenReturn(targetInfoMock);
|
||||
when(targetInfoMock.getAddress()).thenReturn(null);
|
||||
when(targetMock.getAddress()).thenReturn(null);
|
||||
return actionMock;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class MgmtTargetMapper {
|
||||
}
|
||||
|
||||
static void addPollStatus(final Target target, final MgmtTarget targetRest) {
|
||||
final PollStatus pollStatus = target.getTargetInfo().getPollStatus();
|
||||
final PollStatus pollStatus = target.getPollStatus();
|
||||
if (pollStatus != null) {
|
||||
final MgmtPollStatus pollStatusRest = new MgmtPollStatus();
|
||||
pollStatusRest.setLastRequestAt(
|
||||
@@ -111,9 +111,9 @@ public final class MgmtTargetMapper {
|
||||
targetRest.setControllerId(target.getControllerId());
|
||||
targetRest.setDescription(target.getDescription());
|
||||
targetRest.setName(target.getName());
|
||||
targetRest.setUpdateStatus(target.getTargetInfo().getUpdateStatus().name().toLowerCase());
|
||||
targetRest.setUpdateStatus(target.getUpdateStatus().name().toLowerCase());
|
||||
|
||||
final URI address = target.getTargetInfo().getAddress();
|
||||
final URI address = target.getAddress();
|
||||
if (address != null) {
|
||||
if (IpUtil.isIpAddresKnown(address)) {
|
||||
targetRest.setIpAddress(address.getHost());
|
||||
@@ -130,8 +130,8 @@ public final class MgmtTargetMapper {
|
||||
targetRest.setSecurityToken(target.getSecurityToken());
|
||||
|
||||
// last target query is the last controller request date
|
||||
final Long lastTargetQuery = target.getTargetInfo().getLastTargetQuery();
|
||||
final Long installationDate = target.getTargetInfo().getInstallationDate();
|
||||
final Long lastTargetQuery = target.getLastTargetQuery();
|
||||
final Long installationDate = target.getInstallationDate();
|
||||
|
||||
if (lastTargetQuery != null) {
|
||||
targetRest.setLastControllerRequestAt(lastTargetQuery);
|
||||
|
||||
@@ -137,8 +137,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetAttributes> getAttributes(@PathVariable("controllerId") final String controllerId) {
|
||||
final Target foundTarget = findTargetWithExceptionIfNotFound(controllerId);
|
||||
final Map<String, String> controllerAttributes = foundTarget.getTargetInfo().getControllerAttributes();
|
||||
final Map<String, String> controllerAttributes = targetManagement.getControllerAttributes(controllerId);
|
||||
if (controllerAttributes.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
@@ -267,16 +266,13 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(
|
||||
@PathVariable("controllerId") final String controllerId) {
|
||||
final Target findTarget = findTargetWithExceptionIfNotFound(controllerId);
|
||||
final MgmtDistributionSet distributionSetRest = MgmtDistributionSetMapper
|
||||
.toResponse(findTarget.getAssignedDistributionSet());
|
||||
final HttpStatus retStatus;
|
||||
final MgmtDistributionSet distributionSetRest = deploymentManagement.getAssignedDistributionSet(controllerId)
|
||||
.map(MgmtDistributionSetMapper::toResponse).orElse(null);
|
||||
|
||||
if (distributionSetRest == null) {
|
||||
retStatus = HttpStatus.NO_CONTENT;
|
||||
} else {
|
||||
retStatus = HttpStatus.OK;
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
return new ResponseEntity<>(distributionSetRest, retStatus);
|
||||
return new ResponseEntity<>(distributionSetRest, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -302,16 +298,13 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSet> getInstalledDistributionSet(
|
||||
@PathVariable("controllerId") final String controllerId) {
|
||||
final Target findTarget = findTargetWithExceptionIfNotFound(controllerId);
|
||||
final MgmtDistributionSet distributionSetRest = MgmtDistributionSetMapper
|
||||
.toResponse(findTarget.getTargetInfo().getInstalledDistributionSet());
|
||||
final HttpStatus retStatus;
|
||||
final MgmtDistributionSet distributionSetRest = deploymentManagement.getInstalledDistributionSet(controllerId)
|
||||
.map(MgmtDistributionSetMapper::toResponse).orElse(null);
|
||||
|
||||
if (distributionSetRest == null) {
|
||||
retStatus = HttpStatus.NO_CONTENT;
|
||||
} else {
|
||||
retStatus = HttpStatus.OK;
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
return new ResponseEntity<>(distributionSetRest, retStatus);
|
||||
return new ResponseEntity<>(distributionSetRest, HttpStatus.OK);
|
||||
}
|
||||
|
||||
private Target findTargetWithExceptionIfNotFound(final String controllerId) {
|
||||
|
||||
@@ -833,8 +833,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
|
||||
mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetMetadata(testDS.getId(), knownKey).isPresent())
|
||||
.isFalse();
|
||||
assertThat(distributionSetManagement.findDistributionSetMetadata(testDS.getId(), knownKey)).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -853,8 +852,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
|
||||
mvc.perform(delete("/rest/v1/distributionsets/1234/metadata/{key}", knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetMetadata(testDS.getId(), knownKey).isPresent())
|
||||
.isTrue();
|
||||
assertThat(distributionSetManagement.findDistributionSetMetadata(testDS.getId(), knownKey)).isPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -301,8 +301,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.andExpect(jsonPath("$.distributionSetId", equalTo(dsA.getId().intValue())))
|
||||
.andExpect(jsonPath("$.createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("$.createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("$.lastModifiedBy").doesNotExist())
|
||||
.andExpect(jsonPath("$.lastModifiedAt").doesNotExist())
|
||||
.andExpect(jsonPath("$.lastModifiedBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("$.lastModifiedAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("$.totalTargets", equalTo(20)))
|
||||
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0)))
|
||||
.andExpect(jsonPath("$.totalTargetsPerStatus.notstarted", equalTo(20)))
|
||||
@@ -673,8 +673,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.andExpect(jsonPath("$.targetPercentage", equalTo(25.0)))
|
||||
.andExpect(jsonPath("$.createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("$.createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("$.lastModifiedBy").doesNotExist())
|
||||
.andExpect(jsonPath("$.lastModifiedAt").doesNotExist())
|
||||
.andExpect(jsonPath("$.lastModifiedBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("$.lastModifiedAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("$.totalTargets", equalTo(0)))
|
||||
.andExpect(jsonPath("$.totalTargetsPerStatus.running", equalTo(0)))
|
||||
.andExpect(jsonPath("$.totalTargetsPerStatus.notstarted", equalTo(0)))
|
||||
|
||||
@@ -237,8 +237,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1);
|
||||
|
||||
// hashes
|
||||
assertThat(artifactManagement.findArtifactByFilename("customFilename").isPresent())
|
||||
.as("Local artifact is wrong").isTrue();
|
||||
assertThat(artifactManagement.findArtifactByFilename("customFilename")).as("Local artifact is wrong")
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -868,7 +868,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey).isPresent()).isFalse();
|
||||
assertThat(softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey)).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -888,7 +888,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/1234/metadata/{key}", knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey).isPresent()).isTrue();
|
||||
assertThat(softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey)).isPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -74,7 +74,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId()))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
assertThat(targetFilterQueryManagement.findTargetFilterQueryById(filterQuery.getId()).isPresent()).isFalse();
|
||||
assertThat(targetFilterQueryManagement.findTargetFilterQueryById(filterQuery.getId())).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -222,21 +222,24 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
final Target tA = createTargetAndStartAction();
|
||||
|
||||
// test - cancel the active action
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}",
|
||||
tA.getControllerId(), tA.getActions().get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNoContent());
|
||||
mvc.perform(
|
||||
delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}",
|
||||
tA.getControllerId(), deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq)
|
||||
.getContent().get(0).getId()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNoContent());
|
||||
|
||||
final Action action = deploymentManagement.findAction(tA.getActions().get(0).getId()).get();
|
||||
final Action action = deploymentManagement.findAction(
|
||||
deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq).getContent().get(0).getId())
|
||||
.get();
|
||||
// still active because in "canceling" state and waiting for controller
|
||||
// feedback
|
||||
assertThat(action.isActive()).isTrue();
|
||||
|
||||
final Target queryTarget = targetManagement.findTargetByControllerID(tA.getControllerId()).get();
|
||||
// action has not been cancelled confirmed from controller, so DS
|
||||
// remains assigned until
|
||||
// confirmation
|
||||
assertThat(queryTarget.getAssignedDistributionSet()).isNotNull();
|
||||
assertThat(queryTarget.getTargetInfo().getInstalledDistributionSet()).isNull();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(tA.getControllerId())).isPresent();
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(tA.getControllerId())).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -246,11 +249,12 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
final Target tA = createTargetAndStartAction();
|
||||
|
||||
// cancel the active action
|
||||
deploymentManagement.cancelAction(tA.getActions().get(0).getId());
|
||||
deploymentManagement.cancelAction(
|
||||
deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq).getContent().get(0).getId());
|
||||
|
||||
// find the current active action
|
||||
final List<Action> cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq)
|
||||
.getContent().stream().filter(action -> action.isCancelingOrCanceled()).collect(Collectors.toList());
|
||||
.getContent().stream().filter(Action::isCancelingOrCanceled).collect(Collectors.toList());
|
||||
assertThat(cancelActions).hasSize(1);
|
||||
|
||||
// test - cancel an cancel action returns forbidden
|
||||
@@ -266,7 +270,8 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
final Target tA = createTargetAndStartAction();
|
||||
|
||||
// cancel the active action
|
||||
deploymentManagement.cancelAction(tA.getActions().get(0).getId());
|
||||
deploymentManagement.cancelAction(
|
||||
deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq).getContent().get(0).getId());
|
||||
|
||||
// find the current active action
|
||||
final List<Action> cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq)
|
||||
@@ -287,9 +292,11 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
final Target tA = createTargetAndStartAction();
|
||||
|
||||
// test - cancel an cancel action returns forbidden
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true",
|
||||
tA.getControllerId(), tA.getActions().get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
mvc.perform(
|
||||
delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true",
|
||||
tA.getControllerId(), deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq)
|
||||
.getContent().get(0).getId()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -301,7 +308,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID(knownControllerId).isPresent()).isFalse();
|
||||
assertThat(targetManagement.findTargetByControllerID(knownControllerId)).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -387,7 +394,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
.andExpect(jsonPath("$.name", equalTo(knownNameNotModiy)));
|
||||
|
||||
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownControllerId).get();
|
||||
assertThat(findTargetByControllerID.getTargetInfo().getAddress().toString()).isEqualTo(knownNewAddress);
|
||||
assertThat(findTargetByControllerID.getAddress().toString()).isEqualTo(knownNewAddress);
|
||||
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModiy);
|
||||
}
|
||||
|
||||
@@ -518,7 +525,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
.andExpect(jsonPath(JSON_PATH_NAME, equalTo(knownName)))
|
||||
.andExpect(jsonPath(JSON_PATH_CONTROLLERID, equalTo(knownControllerId)))
|
||||
.andExpect(jsonPath(JSON_PATH_DESCRIPTION, equalTo(TARGET_DESCRIPTION_TEST)))
|
||||
.andExpect(jsonPath(JSON_PATH_LAST_REQUEST_AT, equalTo(target.getTargetInfo().getLastTargetQuery())))
|
||||
.andExpect(jsonPath(JSON_PATH_LAST_REQUEST_AT, equalTo(target.getLastTargetQuery())))
|
||||
.andExpect(jsonPath("$.pollStatus", hasKey("lastRequestAt")))
|
||||
.andExpect(jsonPath("$.pollStatus", hasKey("nextExpectedRequestAt")))
|
||||
.andExpect(jsonPath("$.pollStatus.overdue", equalTo(false)))
|
||||
@@ -749,7 +756,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
assertThat(targetManagement.findTargetByControllerID("id1").get().getName()).isEqualTo("testname1");
|
||||
assertThat(targetManagement.findTargetByControllerID("id1").get().getDescription()).isEqualTo("testid1");
|
||||
assertThat(targetManagement.findTargetByControllerID("id1").get().getSecurityToken()).isEqualTo("token");
|
||||
assertThat(targetManagement.findTargetByControllerID("id1").get().getTargetInfo().getAddress().toString())
|
||||
assertThat(targetManagement.findTargetByControllerID("id1").get().getAddress().toString())
|
||||
.isEqualTo("amqp://test123/foobar");
|
||||
assertThat(targetManagement.findTargetByControllerID("id2")).isNotNull();
|
||||
assertThat(targetManagement.findTargetByControllerID("id2").get().getName()).isEqualTo("testname2");
|
||||
@@ -1078,8 +1085,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID("fsdfsd").get().getAssignedDistributionSet())
|
||||
.isEqualTo(set);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("fsdfsd").get()).isEqualTo(set);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1101,8 +1107,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
assertThat(findActiveActionsByTarget).hasSize(1);
|
||||
assertThat(findActiveActionsByTarget.get(0).getActionType()).isEqualTo(ActionType.TIMEFORCED);
|
||||
assertThat(findActiveActionsByTarget.get(0).getForcedTime()).isEqualTo(forceTime);
|
||||
assertThat(targetManagement.findTargetByControllerID("fsdfsd").get().getAssignedDistributionSet())
|
||||
.isEqualTo(set);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("fsdfsd").get()).isEqualTo(set);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.eclipse.hawkbit.repository.model.ActionWithStatusCount;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||
@@ -372,15 +370,15 @@ public interface DeploymentManagement {
|
||||
/**
|
||||
* Starts all scheduled actions of an RolloutGroup parent.
|
||||
*
|
||||
* @param rollout
|
||||
* @param rolloutId
|
||||
* the rollout the actions belong to
|
||||
* @param rolloutGroupParent
|
||||
* @param rolloutGroupParentId
|
||||
* the parent rollout group the actions should reference. null
|
||||
* references the first group
|
||||
* @return the amount of started actions
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
long startScheduledActionsByRolloutGroupParent(@NotNull Rollout rollout, RolloutGroup rolloutGroupParent);
|
||||
long startScheduledActionsByRolloutGroupParent(@NotNull Long rolloutId, Long rolloutGroupParentId);
|
||||
|
||||
/**
|
||||
* All {@link ActionStatus} entries in the repository.
|
||||
@@ -391,4 +389,29 @@ public interface DeploymentManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<ActionStatus> findActionStatusAll(@NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Returns {@link DistributionSet} that is assigned to given {@link Target}.
|
||||
*
|
||||
* @param controllerId
|
||||
* of target
|
||||
* @return assigned {@link DistributionSet}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if target with given ID does not exist
|
||||
*/
|
||||
Optional<DistributionSet> getAssignedDistributionSet(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Returns {@link DistributionSet} that is installed on given
|
||||
* {@link Target}.
|
||||
*
|
||||
* @param controllerId
|
||||
* of target
|
||||
* @return installed {@link DistributionSet}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if target with given ID does not exist
|
||||
*/
|
||||
Optional<DistributionSet> getInstalledDistributionSet(@NotEmpty String controllerId);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.report.model.DataReportSeries;
|
||||
import org.eclipse.hawkbit.repository.report.model.InnerOuterDataReportSeries;
|
||||
@@ -183,8 +183,8 @@ public interface ReportManagement {
|
||||
|
||||
/**
|
||||
* Generates a report as a {@link ListReportSeries} targets polled based on
|
||||
* the {@link TargetInfo#getLastTargetQuery()} within an hour, day, week,
|
||||
* month, year, more than a year, never.
|
||||
* the {@link Target#getLastTargetQuery()} within an hour, day, week, month,
|
||||
* year, more than a year, never.
|
||||
*
|
||||
* The order of the numbers within the {@link DataReportSeries} is the order
|
||||
* hour, day, week, month, year, more than a year, never.
|
||||
|
||||
@@ -168,6 +168,21 @@ public interface TagManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<TargetTag> findAllTargetTags(@NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Returns all {@link TargetTag}s assigned to {@link Target} with given ID.
|
||||
*
|
||||
* @param pageable
|
||||
* page parameter
|
||||
* @param controllerId
|
||||
*
|
||||
* @return {@link TargetTag}s assigned to {@link Target} with given ID
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if target with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<TargetTag> findAllTargetTags(@NotNull Pageable pageable, @NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Retrieves all target tags based on the given specification.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -26,7 +27,6 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
@@ -108,7 +108,7 @@ public interface TargetManagement {
|
||||
|
||||
/**
|
||||
* Counts number of targets with given
|
||||
* {@link TargetInfo#getInstalledDistributionSet()}.
|
||||
* {@link Target#getInstalledDistributionSet()}.
|
||||
*
|
||||
* @param distId
|
||||
* to search for
|
||||
@@ -342,9 +342,7 @@ public interface TargetManagement {
|
||||
List<Target> findTargetByControllerID(@NotEmpty Collection<String> controllerIDs);
|
||||
|
||||
/**
|
||||
* Find a {@link Target} based a given ID. The returned target will not
|
||||
* contain details (e.g {@link Target#getTags()} and
|
||||
* {@link Target#getActions()})
|
||||
* Find a {@link Target} based a given ID.
|
||||
*
|
||||
* @param controllerId
|
||||
* to look for.
|
||||
@@ -353,21 +351,6 @@ public interface TargetManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Optional<Target> findTargetByControllerID(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Find {@link Target} based on given ID returns found Target with details,
|
||||
* i.e. {@link Target#getTags()} and {@link Target#getActions()} are
|
||||
* possible.
|
||||
*
|
||||
* Note: try to use {@link #findTargetByControllerID(String)} as much as
|
||||
* possible.
|
||||
*
|
||||
* @param controllerId
|
||||
* to look for.
|
||||
* @return {@link Target}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Optional<Target> findTargetByControllerIDWithDetails(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Filter {@link Target}s for all the given parameters. If all parameters
|
||||
* except pageable are null, all available {@link Target}s are returned.
|
||||
@@ -523,8 +506,7 @@ public interface TargetManagement {
|
||||
* order:
|
||||
* <p>
|
||||
* 1) {@link Target}s which have the given {@link DistributionSet} as
|
||||
* {@link Target#getTargetInfo()}
|
||||
* {@link TargetInfo#getInstalledDistributionSet()}
|
||||
* {@link Target#getTarget()} {@link Target#getInstalledDistributionSet()}
|
||||
* <p>
|
||||
* 2) {@link Target}s which have the given {@link DistributionSet} as
|
||||
* {@link Target#getAssignedDistributionSet()}
|
||||
@@ -549,20 +531,6 @@ public interface TargetManagement {
|
||||
Slice<Target> findTargetsAllOrderByLinkedDistributionSet(@NotNull Pageable pageable,
|
||||
@NotNull Long orderByDistributionId, FilterParams filterParams);
|
||||
|
||||
/**
|
||||
* retrieves a list of {@link Target}s by their controller ID with details,
|
||||
* i.e. {@link Target#getTags()} are possible.
|
||||
*
|
||||
* Note: try to use {@link #findTargetByControllerID(String)} as much as
|
||||
* possible.
|
||||
*
|
||||
* @param controllerIDs
|
||||
* {@link Target}s Names parameter
|
||||
* @return the found {@link Target}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
List<Target> findTargetsByControllerIDsWithTags(@NotNull List<String> controllerIDs);
|
||||
|
||||
/**
|
||||
* Find targets by tag name.
|
||||
*
|
||||
@@ -656,4 +624,16 @@ public interface TargetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
List<Target> findTargetAllById(@NotNull Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Get controller attributes of given {@link Target}.
|
||||
*
|
||||
* @param controllerId
|
||||
* of the target
|
||||
* @return controller attributes as key/value pairs
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if target with given ID does not exist
|
||||
*/
|
||||
Map<String, String> getControllerAttributes(@NotEmpty String controllerId);
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Builder to update an existing {@link Rollout} entry. Defines all fields that
|
||||
* can be updated.
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
@@ -52,7 +51,7 @@ public interface TargetCreate {
|
||||
|
||||
/**
|
||||
* @param address
|
||||
* for {@link TargetInfo#getAddress()}
|
||||
* for {@link Target#getAddress()}
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the given string violates RFC 2396
|
||||
@@ -63,14 +62,14 @@ public interface TargetCreate {
|
||||
|
||||
/**
|
||||
* @param lastTargetQuery
|
||||
* for {@link TargetInfo#getLastTargetQuery()}
|
||||
* for {@link Target#getLastTargetQuery()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate lastTargetQuery(Long lastTargetQuery);
|
||||
|
||||
/**
|
||||
* @param status
|
||||
* for {@link TargetInfo#getUpdateStatus()}
|
||||
* for {@link Target#getUpdateStatus()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate status(TargetUpdateStatus status);
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
@@ -43,7 +42,7 @@ public interface TargetUpdate {
|
||||
|
||||
/**
|
||||
* @param address
|
||||
* for {@link TargetInfo#getAddress()}
|
||||
* for {@link Target#getAddress()}
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the given string violates RFC 2396
|
||||
@@ -54,14 +53,14 @@ public interface TargetUpdate {
|
||||
|
||||
/**
|
||||
* @param lastTargetQuery
|
||||
* for {@link TargetInfo#getLastTargetQuery()}
|
||||
* for {@link Target#getLastTargetQuery()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate lastTargetQuery(Long lastTargetQuery);
|
||||
|
||||
/**
|
||||
* @param status
|
||||
* for {@link TargetInfo#getUpdateStatus()}
|
||||
* for {@link Target#getUpdateStatus()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate status(TargetUpdateStatus status);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.RemoteIdEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@ public class TargetPollEvent extends RemoteTenantAwareEvent {
|
||||
public TargetPollEvent(final Target target, final String applicationId) {
|
||||
super(target.getControllerId(), target.getTenant(), applicationId);
|
||||
this.controllerId = target.getControllerId();
|
||||
this.targetAdress = target.getTargetInfo().getAddress().toString();
|
||||
this.targetAdress = target.getAddress().toString();
|
||||
}
|
||||
|
||||
public String getControllerId() {
|
||||
|
||||
@@ -72,8 +72,7 @@ public interface DistributionSetType extends NamedEntity {
|
||||
* @return <code>true</code> if found
|
||||
*/
|
||||
default boolean containsMandatoryModuleType(final Long softwareModuleTypeId) {
|
||||
return getMandatoryModuleTypes().stream().filter(element -> element.getId().equals(softwareModuleTypeId))
|
||||
.findAny().isPresent();
|
||||
return getMandatoryModuleTypes().stream().anyMatch(element -> element.getId().equals(softwareModuleTypeId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,8 +96,7 @@ public interface DistributionSetType extends NamedEntity {
|
||||
* @return <code>true</code> if found
|
||||
*/
|
||||
default boolean containsOptionalModuleType(final Long softwareModuleTypeId) {
|
||||
return getOptionalModuleTypes().stream().filter(element -> element.getId().equals(softwareModuleTypeId))
|
||||
.findAny().isPresent();
|
||||
return getOptionalModuleTypes().stream().anyMatch(element -> element.getId().equals(softwareModuleTypeId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Represents information to validate the correct distribution of targets to
|
||||
* rollout groups.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -21,31 +21,11 @@ import java.util.Set;
|
||||
*/
|
||||
public interface Target extends NamedEntity {
|
||||
|
||||
/**
|
||||
* @return currently assigned {@link DistributionSet}.
|
||||
*/
|
||||
DistributionSet getAssignedDistributionSet();
|
||||
|
||||
/**
|
||||
* @return business identifier of the {@link Target}
|
||||
*/
|
||||
String getControllerId();
|
||||
|
||||
/**
|
||||
* @return immutable set of assigned {@link TargetTag}s.
|
||||
*/
|
||||
Set<TargetTag> getTags();
|
||||
|
||||
/**
|
||||
* @return immutable {@link Action} history of the {@link Target}.
|
||||
*/
|
||||
List<Action> getActions();
|
||||
|
||||
/**
|
||||
* @return the targetInfo object
|
||||
*/
|
||||
TargetInfo getTargetInfo();
|
||||
|
||||
/**
|
||||
* @return the securityToken
|
||||
*/
|
||||
@@ -58,4 +38,41 @@ public interface Target extends NamedEntity {
|
||||
return new TargetWithActionType(getControllerId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the address under which the target can be reached
|
||||
*/
|
||||
URI getAddress();
|
||||
|
||||
/**
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when the {@link Target}
|
||||
* polled the server the last time or <code>null</code> if target
|
||||
* has never queried yet.
|
||||
*/
|
||||
Long getLastTargetQuery();
|
||||
|
||||
/**
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when
|
||||
* {@link #getInstalledDistributionSet()} was applied.
|
||||
*/
|
||||
Long getInstallationDate();
|
||||
|
||||
/**
|
||||
* @return current status of the {@link Target}.
|
||||
*/
|
||||
TargetUpdateStatus getUpdateStatus();
|
||||
|
||||
/**
|
||||
* @return the poll time which holds the last poll time of the target, the
|
||||
* next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled
|
||||
* before this method returns {@code null}
|
||||
*/
|
||||
PollStatus getPollStatus();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the {@link Target} has not jet provided
|
||||
* {@link #getControllerAttributes()}.
|
||||
*/
|
||||
boolean isRequestControllerAttributes();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public interface TargetInfo extends Serializable {
|
||||
/**
|
||||
* @return the address under which the target can be reached
|
||||
*/
|
||||
URI getAddress();
|
||||
|
||||
/**
|
||||
* @return {@link Target} this info element belongs to.
|
||||
*/
|
||||
Target getTarget();
|
||||
|
||||
/**
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when the {@link Target}
|
||||
* polled the server the last time or <code>null</code> if target
|
||||
* has never queried yet.
|
||||
*/
|
||||
Long getLastTargetQuery();
|
||||
|
||||
/**
|
||||
* @return {@link AttributedCharacterIterator} that have been provided by
|
||||
* the {@link Target} itself, e.g. hardware revision, serial number,
|
||||
* mac address etc.
|
||||
*/
|
||||
Map<String, String> getControllerAttributes();
|
||||
|
||||
/**
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when
|
||||
* {@link #getInstalledDistributionSet()} was applied.
|
||||
*/
|
||||
Long getInstallationDate();
|
||||
|
||||
/**
|
||||
* @return current status of the {@link Target}.
|
||||
*/
|
||||
TargetUpdateStatus getUpdateStatus();
|
||||
|
||||
/**
|
||||
* @return currently installed {@link DistributionSet}.
|
||||
*/
|
||||
DistributionSet getInstalledDistributionSet();
|
||||
|
||||
/**
|
||||
* @return the poll time which holds the last poll time of the target, the
|
||||
* next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled
|
||||
* before this method returns {@code null}
|
||||
*/
|
||||
PollStatus getPollStatus();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the {@link Target} has not jet provided
|
||||
* {@link #getControllerAttributes()}.
|
||||
*/
|
||||
boolean isRequestControllerAttributes();
|
||||
|
||||
}
|
||||
@@ -321,8 +321,8 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
* rolloutgroup in a specific status
|
||||
*/
|
||||
@EntityGraph(attributePaths = { "target" }, type = EntityGraphType.LOAD)
|
||||
Page<Action> findByRolloutAndRolloutGroupParentAndStatus(Pageable pageable, JpaRollout rollout,
|
||||
JpaRolloutGroup rolloutGroupParent, Status actionStatus);
|
||||
Page<Action> findByRolloutIdAndRolloutGroupParentIdAndStatus(Pageable pageable, Long rollout,
|
||||
Long rolloutGroupParent, Status actionStatus);
|
||||
|
||||
/**
|
||||
* Retrieving all actions referring to the first group of a rollout.
|
||||
@@ -337,7 +337,7 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
||||
* rolloutgroup in a specific status
|
||||
*/
|
||||
@EntityGraph(attributePaths = { "target" }, type = EntityGraphType.LOAD)
|
||||
Page<Action> findByRolloutAndRolloutGroupParentIsNullAndStatus(Pageable pageable, JpaRollout rollout,
|
||||
Page<Action> findByRolloutIdAndRolloutGroupParentIsNullAndStatus(Pageable pageable, Long rollout,
|
||||
Status actionStatus);
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,12 +11,10 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
@@ -41,24 +39,19 @@ public final class DeploymentHelper {
|
||||
* of the target
|
||||
* @param setInstalledDate
|
||||
* to set
|
||||
* @param entityManager
|
||||
* for the operation
|
||||
* @param targetInfoRepository
|
||||
* for the operation
|
||||
*
|
||||
* @return updated target
|
||||
*/
|
||||
static JpaTarget updateTargetInfo(@NotNull final JpaTarget target, @NotNull final TargetUpdateStatus status,
|
||||
final boolean setInstalledDate, final TargetInfoRepository targetInfoRepository,
|
||||
final EntityManager entityManager) {
|
||||
final JpaTargetInfo ts = (JpaTargetInfo) target.getTargetInfo();
|
||||
ts.setUpdateStatus(status);
|
||||
final boolean setInstalledDate) {
|
||||
target.setUpdateStatus(status);
|
||||
|
||||
if (setInstalledDate) {
|
||||
ts.setInstallationDate(System.currentTimeMillis());
|
||||
target.setInstallationDate(System.currentTimeMillis());
|
||||
}
|
||||
targetInfoRepository.save(ts);
|
||||
return entityManager.merge(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,14 +65,11 @@ public final class DeploymentHelper {
|
||||
* for the operation
|
||||
* @param targetRepository
|
||||
* for the operation
|
||||
* @param entityManager
|
||||
* for the operation
|
||||
* @param targetInfoRepository
|
||||
* for the operation
|
||||
*/
|
||||
static void successCancellation(final JpaAction action, final ActionRepository actionRepository,
|
||||
final TargetRepository targetRepository, final TargetInfoRepository targetInfoRepository,
|
||||
final EntityManager entityManager) {
|
||||
final TargetRepository targetRepository) {
|
||||
|
||||
// set action inactive
|
||||
action.setActive(false);
|
||||
@@ -90,12 +80,11 @@ public final class DeploymentHelper {
|
||||
.filter(a -> !a.getId().equals(action.getId())).collect(Collectors.toList());
|
||||
|
||||
if (nextActiveActions.isEmpty()) {
|
||||
target.setAssignedDistributionSet(target.getTargetInfo().getInstalledDistributionSet());
|
||||
updateTargetInfo(target, TargetUpdateStatus.IN_SYNC, false, targetInfoRepository, entityManager);
|
||||
target.setAssignedDistributionSet(target.getInstalledDistributionSet());
|
||||
updateTargetInfo(target, TargetUpdateStatus.IN_SYNC, false);
|
||||
} else {
|
||||
target.setAssignedDistributionSet(nextActiveActions.get(0).getDistributionSet());
|
||||
}
|
||||
target.setNew(false);
|
||||
targetRepository.save(target);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
@@ -109,6 +110,12 @@ public interface DistributionSetRepository
|
||||
@Query("select DISTINCT d from JpaDistributionSet d join fetch d.modules m join d.actions a where a.id = :action")
|
||||
JpaDistributionSet findByActionId(@Param("action") Long action);
|
||||
|
||||
@Query("select DISTINCT ds from JpaDistributionSet ds join fetch ds.modules join ds.assignedToTargets t where t.controllerId = :controllerId")
|
||||
Optional<DistributionSet> findAssignedToTarget(@Param("controllerId") String controllerId);
|
||||
|
||||
@Query("select DISTINCT ds from JpaDistributionSet ds join fetch ds.modules join ds.installedAtTargets t where t.controllerId = :controllerId")
|
||||
Optional<DistributionSet> findInstalledAtTarget(@Param("controllerId") String controllerId);
|
||||
|
||||
/**
|
||||
* Counts {@link DistributionSet} instances of given type in the repository.
|
||||
*
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Custom repository implementation as standard spring repository fails as of
|
||||
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=415027 .
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
|
||||
public class EclipseLinkTargetInfoRepository implements TargetInfoRepository {
|
||||
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void setTargetUpdateStatus(final TargetUpdateStatus status, final List<Long> targets) {
|
||||
final Query query = entityManager.createQuery(
|
||||
"update JpaTargetInfo ti set ti.updateStatus = :status where ti.targetId in :targets and ti.updateStatus != :status");
|
||||
query.setParameter("targets", targets);
|
||||
query.setParameter("status", status);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public <S extends JpaTargetInfo> S save(final S entity) {
|
||||
|
||||
if (entity.isNew()) {
|
||||
entityManager.persist(entity);
|
||||
return entity;
|
||||
} else {
|
||||
return entityManager.merge(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException;
|
||||
@@ -40,7 +39,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
@@ -48,7 +46,6 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
@@ -92,9 +89,6 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Autowired
|
||||
private TargetManagement targetManagement;
|
||||
|
||||
@Autowired
|
||||
private TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
private ActionStatusRepository actionStatusRepository;
|
||||
|
||||
@@ -135,10 +129,10 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public Target updateLastTargetQuery(final String controllerId, final URI address) {
|
||||
final Target target = targetRepository.findByControllerId(controllerId)
|
||||
final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
return updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), address).getTarget();
|
||||
return updateTargetStatus(target, null, System.currentTimeMillis(), address);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,32 +216,29 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
return result;
|
||||
}
|
||||
|
||||
return updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), address).getTarget();
|
||||
return updateTargetStatus(target, null, System.currentTimeMillis(), address);
|
||||
}
|
||||
|
||||
private TargetInfo updateTargetStatus(final TargetInfo targetInfo, final TargetUpdateStatus status,
|
||||
private Target updateTargetStatus(final JpaTarget toUpdate, final TargetUpdateStatus status,
|
||||
final Long lastTargetQuery, final URI address) {
|
||||
final JpaTargetInfo mtargetInfo = (JpaTargetInfo) entityManager.merge(targetInfo);
|
||||
if (status != null) {
|
||||
mtargetInfo.setUpdateStatus(status);
|
||||
toUpdate.setUpdateStatus(status);
|
||||
}
|
||||
if (lastTargetQuery != null) {
|
||||
mtargetInfo.setLastTargetQuery(lastTargetQuery);
|
||||
toUpdate.setLastTargetQuery(lastTargetQuery);
|
||||
}
|
||||
|
||||
if (mtargetInfo.getUpdateStatus() == TargetUpdateStatus.UNKNOWN) {
|
||||
mtargetInfo.setUpdateStatus(TargetUpdateStatus.REGISTERED);
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new TargetUpdatedEvent(mtargetInfo.getTarget(), applicationContext.getId())));
|
||||
if (TargetUpdateStatus.UNKNOWN.equals(toUpdate.getUpdateStatus())) {
|
||||
toUpdate.setUpdateStatus(TargetUpdateStatus.REGISTERED);
|
||||
}
|
||||
|
||||
if (address != null) {
|
||||
mtargetInfo.setAddress(address.toString());
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new TargetPollEvent(mtargetInfo.getTarget(), applicationContext.getId())));
|
||||
toUpdate.setAddress(address.toString());
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetPollEvent(toUpdate, applicationContext.getId())));
|
||||
}
|
||||
|
||||
return targetInfoRepository.save(mtargetInfo);
|
||||
return targetRepository.save(toUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -291,8 +282,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
// the canceled action itself.
|
||||
actionStatus.addMessage(
|
||||
RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully.");
|
||||
DeploymentHelper.successCancellation(action, actionRepository, targetRepository, targetInfoRepository,
|
||||
entityManager);
|
||||
DeploymentHelper.successCancellation(action, actionRepository, targetRepository);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -332,8 +322,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
|
||||
switch (actionStatus.getStatus()) {
|
||||
case ERROR:
|
||||
target = DeploymentHelper.updateTargetInfo(target, TargetUpdateStatus.ERROR, false, targetInfoRepository,
|
||||
entityManager);
|
||||
target = DeploymentHelper.updateTargetInfo(target, TargetUpdateStatus.ERROR, false);
|
||||
handleErrorOnAction(action, target);
|
||||
break;
|
||||
case FINISHED:
|
||||
@@ -358,7 +347,6 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
mergedAction.setStatus(Status.ERROR);
|
||||
mergedTarget.setAssignedDistributionSet(null);
|
||||
|
||||
mergedTarget.setNew(false);
|
||||
targetRepository.save(mergedTarget);
|
||||
}
|
||||
|
||||
@@ -380,23 +368,19 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
private void handleFinishedAndStoreInTargetStatus(final JpaTarget target, final JpaAction action) {
|
||||
action.setActive(false);
|
||||
action.setStatus(Status.FINISHED);
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) target.getTargetInfo();
|
||||
final JpaDistributionSet ds = (JpaDistributionSet) entityManager.merge(action.getDistributionSet());
|
||||
|
||||
targetInfo.setInstalledDistributionSet(ds);
|
||||
targetInfo.setInstallationDate(System.currentTimeMillis());
|
||||
target.setInstalledDistributionSet(ds);
|
||||
target.setInstallationDate(System.currentTimeMillis());
|
||||
|
||||
// check if the assigned set is equal to the installed set (not
|
||||
// necessarily the case as another update might be pending already).
|
||||
if (target.getAssignedDistributionSet() != null && target.getAssignedDistributionSet().getId()
|
||||
.equals(targetInfo.getInstalledDistributionSet().getId())) {
|
||||
targetInfo.setUpdateStatus(TargetUpdateStatus.IN_SYNC);
|
||||
if (target.getAssignedDistributionSet() != null
|
||||
&& target.getAssignedDistributionSet().getId().equals(target.getInstalledDistributionSet().getId())) {
|
||||
target.setUpdateStatus(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
targetInfoRepository.save(targetInfo);
|
||||
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId())));
|
||||
targetRepository.save(target);
|
||||
|
||||
entityManager.detach(ds);
|
||||
}
|
||||
@@ -408,26 +392,19 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) target.getTargetInfo();
|
||||
targetInfo.getControllerAttributes().putAll(data);
|
||||
target.getControllerAttributes().putAll(data);
|
||||
|
||||
if (targetInfo.getControllerAttributes().size() > securityProperties.getDos()
|
||||
.getMaxAttributeEntriesPerTarget()) {
|
||||
if (target.getControllerAttributes().size() > securityProperties.getDos().getMaxAttributeEntriesPerTarget()) {
|
||||
LOG_DOS.info("Target tries to insert more than the allowed number of entries ({}). DOS attack anticipated!",
|
||||
securityProperties.getDos().getMaxAttributeEntriesPerTarget());
|
||||
throw new ToManyAttributeEntriesException(
|
||||
String.valueOf(securityProperties.getDos().getMaxAttributeEntriesPerTarget()));
|
||||
}
|
||||
|
||||
targetInfo.setLastTargetQuery(System.currentTimeMillis());
|
||||
targetInfo.setRequestControllerAttributes(false);
|
||||
target.setLastTargetQuery(System.currentTimeMillis());
|
||||
target.setRequestControllerAttributes(false);
|
||||
|
||||
final Target result = targetInfoRepository.save(targetInfo).getTarget();
|
||||
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetUpdatedEvent(result, applicationContext.getId())));
|
||||
|
||||
return result;
|
||||
return targetRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
@@ -63,8 +62,6 @@ import org.eclipse.hawkbit.repository.model.ActionWithStatusCount;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
@@ -125,9 +122,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
@Autowired
|
||||
private TargetManagement targetManagement;
|
||||
|
||||
@Autowired
|
||||
private TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
private AuditorAware<String> auditorProvider;
|
||||
|
||||
@@ -257,9 +251,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
currentUser = null;
|
||||
}
|
||||
|
||||
targetIds.forEach(tIds -> targetRepository.setAssignedDistributionSet(set, System.currentTimeMillis(),
|
||||
currentUser, tIds));
|
||||
targetIds.forEach(tIds -> targetInfoRepository.setTargetUpdateStatus(TargetUpdateStatus.PENDING, tIds));
|
||||
targetIds.forEach(tIds -> targetRepository.setAssignedDistributionSetAndUpdateStatus(TargetUpdateStatus.PENDING,
|
||||
set, System.currentTimeMillis(), currentUser, tIds));
|
||||
final Map<String, JpaAction> targetIdsToActions = targets.stream().map(
|
||||
t -> actionRepository.save(createTargetAction(targetsWithActionMap, t, set, rollout, rolloutGroup)))
|
||||
.collect(Collectors.toMap(a -> a.getTarget().getControllerId(), Function.identity()));
|
||||
@@ -311,10 +304,15 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
private void assignDistributionSetEvent(final Action action) {
|
||||
((JpaTargetInfo) action.getTarget().getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new TargetUpdatedEvent(action.getTarget(), applicationContext.getId())));
|
||||
// Update is not available in the object as the update was executed
|
||||
// through JQL
|
||||
final JpaTarget target = (JpaTarget) action.getTarget();
|
||||
target.setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
entityManager.detach(target);
|
||||
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId())));
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new TargetAssignDistributionSetEvent(action, applicationContext.getId())));
|
||||
}
|
||||
@@ -388,15 +386,10 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
* the action id of the assignment
|
||||
*/
|
||||
private void cancelAssignDistributionSetEvent(final Target target, final Long actionId) {
|
||||
loadLazyTargetInfo(target);
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new CancelTargetAssignmentEvent(target, actionId, applicationContext.getId())));
|
||||
}
|
||||
|
||||
private static void loadLazyTargetInfo(final Target target) {
|
||||
target.getTargetInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
@@ -419,8 +412,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
actionStatusRepository.save(new JpaActionStatus(action, Status.CANCELED, System.currentTimeMillis(),
|
||||
"A force quit has been performed."));
|
||||
|
||||
DeploymentHelper.successCancellation(action, actionRepository, targetRepository, targetInfoRepository,
|
||||
entityManager);
|
||||
DeploymentHelper.successCancellation(action, actionRepository, targetRepository);
|
||||
|
||||
return actionRepository.save(action);
|
||||
}
|
||||
@@ -428,29 +420,29 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
public long startScheduledActionsByRolloutGroupParent(@NotNull final Rollout rollout,
|
||||
final RolloutGroup rolloutGroupParent) {
|
||||
public long startScheduledActionsByRolloutGroupParent(@NotNull final Long rolloutId,
|
||||
final Long rolloutGroupParentId) {
|
||||
long totalActionsCount = 0L;
|
||||
long lastStartedActionsCount;
|
||||
do {
|
||||
lastStartedActionsCount = startScheduledActionsByRolloutGroupParentInNewTransaction(rollout,
|
||||
rolloutGroupParent, ACTION_PAGE_LIMIT);
|
||||
lastStartedActionsCount = startScheduledActionsByRolloutGroupParentInNewTransaction(rolloutId,
|
||||
rolloutGroupParentId, ACTION_PAGE_LIMIT);
|
||||
totalActionsCount += lastStartedActionsCount;
|
||||
} while (lastStartedActionsCount > 0);
|
||||
|
||||
return totalActionsCount;
|
||||
}
|
||||
|
||||
private long startScheduledActionsByRolloutGroupParentInNewTransaction(final Rollout rollout,
|
||||
final RolloutGroup rolloutGroupParent, final int limit) {
|
||||
private long startScheduledActionsByRolloutGroupParentInNewTransaction(final Long rolloutId,
|
||||
final Long rolloutGroupParentId, final int limit) {
|
||||
final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
def.setName("startScheduledActions");
|
||||
def.setReadOnly(false);
|
||||
def.setIsolationLevel(Isolation.READ_UNCOMMITTED.value());
|
||||
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
return new TransactionTemplate(txManager, def).execute(status -> {
|
||||
final Page<Action> rolloutGroupActions = findActionsByRolloutAndRolloutGroupParent(rollout,
|
||||
rolloutGroupParent, limit);
|
||||
final Page<Action> rolloutGroupActions = findActionsByRolloutAndRolloutGroupParent(rolloutId,
|
||||
rolloutGroupParentId, limit);
|
||||
|
||||
rolloutGroupActions.map(action -> (JpaAction) action).forEach(this::startScheduledAction);
|
||||
|
||||
@@ -458,33 +450,35 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
});
|
||||
}
|
||||
|
||||
private Page<Action> findActionsByRolloutAndRolloutGroupParent(final Rollout rollout,
|
||||
final RolloutGroup rolloutGroupParent, final int limit) {
|
||||
final JpaRollout jpaRollout = (JpaRollout) rollout;
|
||||
final JpaRolloutGroup jpaRolloutGroup = (JpaRolloutGroup) rolloutGroupParent;
|
||||
private Page<Action> findActionsByRolloutAndRolloutGroupParent(final Long rolloutId,
|
||||
final Long rolloutGroupParentId, final int limit) {
|
||||
|
||||
final PageRequest pageRequest = new PageRequest(0, limit);
|
||||
if (rolloutGroupParent == null) {
|
||||
return actionRepository.findByRolloutAndRolloutGroupParentIsNullAndStatus(pageRequest, jpaRollout,
|
||||
if (rolloutGroupParentId == null) {
|
||||
return actionRepository.findByRolloutIdAndRolloutGroupParentIsNullAndStatus(pageRequest, rolloutId,
|
||||
Action.Status.SCHEDULED);
|
||||
} else {
|
||||
return actionRepository.findByRolloutAndRolloutGroupParentAndStatus(pageRequest, jpaRollout,
|
||||
jpaRolloutGroup, Action.Status.SCHEDULED);
|
||||
return actionRepository.findByRolloutIdAndRolloutGroupParentIdAndStatus(pageRequest, rolloutId,
|
||||
rolloutGroupParentId, Action.Status.SCHEDULED);
|
||||
}
|
||||
}
|
||||
|
||||
private Action startScheduledAction(final JpaAction action) {
|
||||
private void startScheduledAction(final JpaAction action) {
|
||||
// check if we need to override running update actions
|
||||
final Set<Long> overrideObsoleteUpdateActions = overrideObsoleteUpdateActions(
|
||||
Collections.singletonList(action.getTarget().getId()));
|
||||
|
||||
if (action.getTarget().getAssignedDistributionSet() != null && action.getDistributionSet().getId()
|
||||
.equals(action.getTarget().getAssignedDistributionSet().getId())) {
|
||||
JpaTarget target = (JpaTarget) action.getTarget();
|
||||
|
||||
if (target.getAssignedDistributionSet() != null
|
||||
&& action.getDistributionSet().getId().equals(target.getAssignedDistributionSet().getId())) {
|
||||
// the target has already the distribution set assigned, we don't
|
||||
// need to start the scheduled action, just finish it.
|
||||
action.setStatus(Status.FINISHED);
|
||||
action.setActive(false);
|
||||
setSkipActionStatus(action);
|
||||
return actionRepository.save(action);
|
||||
actionRepository.save(action);
|
||||
return;
|
||||
}
|
||||
|
||||
action.setActive(true);
|
||||
@@ -493,20 +487,18 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
setRunningActionStatus(savedAction, null);
|
||||
|
||||
final JpaTarget target = (JpaTarget) savedAction.getTarget();
|
||||
target = (JpaTarget) entityManager.merge(savedAction.getTarget());
|
||||
|
||||
target.setAssignedDistributionSet(savedAction.getDistributionSet());
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) target.getTargetInfo();
|
||||
targetInfo.setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
target.setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
targetRepository.save(target);
|
||||
targetInfoRepository.save(targetInfo);
|
||||
|
||||
// in case we canceled an action before for this target, then don't fire
|
||||
// assignment event
|
||||
if (!overrideObsoleteUpdateActions.contains(savedAction.getId())) {
|
||||
assignDistributionSetEvent(savedAction);
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new TargetAssignDistributionSetEvent(savedAction, applicationContext.getId())));
|
||||
}
|
||||
return savedAction;
|
||||
}
|
||||
|
||||
private void setRunningActionStatus(final JpaAction action, final String actionMessage) {
|
||||
@@ -682,4 +674,18 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
public Slice<Action> findActionsAll(final Pageable pageable) {
|
||||
return convertAcPage(actionRepository.findAll(pageable), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSet> getAssignedDistributionSet(final String controllerId) {
|
||||
throwExceptionIfTargetFoesNotExist(controllerId);
|
||||
|
||||
return distributoinSetRepository.findAssignedToTarget(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSet> getInstalledDistributionSet(final String controllerId) {
|
||||
throwExceptionIfTargetFoesNotExist(controllerId);
|
||||
|
||||
return distributoinSetRepository.findInstalledAtTarget(controllerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,7 +675,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
final JpaDistributionSet result = entityManager.merge((JpaDistributionSet) ds);
|
||||
result.setLastModifiedAt(0L);
|
||||
|
||||
return result;
|
||||
return distributionSetRepository.save(result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,6 @@ import javax.persistence.Query;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.ListJoin;
|
||||
import javax.persistence.criteria.Root;
|
||||
@@ -33,8 +32,6 @@ import org.eclipse.hawkbit.repository.ReportManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.report.model.DataReportSeries;
|
||||
@@ -85,19 +82,18 @@ public class JpaReportManagement implements ReportManagement {
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
|
||||
final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);
|
||||
final Join<JpaTarget, JpaTargetInfo> targetInfo = targetRoot.join(JpaTarget_.targetInfo);
|
||||
final Expression<Long> countColumn = cb.count(targetInfo.get(JpaTargetInfo_.targetId));
|
||||
final Expression<Long> countColumn = cb.count(targetRoot.get(JpaTarget_.id));
|
||||
final CriteriaQuery<Object[]> multiselect = query
|
||||
.multiselect(targetInfo.get(JpaTargetInfo_.updateStatus), countColumn)
|
||||
.groupBy(targetInfo.get(JpaTargetInfo_.updateStatus))
|
||||
.orderBy(cb.desc(targetInfo.get(JpaTargetInfo_.updateStatus)));
|
||||
.multiselect(targetRoot.get(JpaTarget_.updateStatus), countColumn)
|
||||
.groupBy(targetRoot.get(JpaTarget_.updateStatus))
|
||||
.orderBy(cb.desc(targetRoot.get(JpaTarget_.updateStatus)));
|
||||
|
||||
// | col1 | col2 |
|
||||
// | U_STATUS | COUNT |
|
||||
final List<Object[]> resultList = entityManager.createQuery(multiselect).getResultList();
|
||||
|
||||
final List<DataReportSeriesItem<TargetUpdateStatus>> reportSeriesItems = resultList.stream()
|
||||
.map(r -> new DataReportSeriesItem<TargetUpdateStatus>((TargetUpdateStatus) r[0], (Long) r[1]))
|
||||
.map(r -> new DataReportSeriesItem<>((TargetUpdateStatus) r[0], (Long) r[1]))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new DataReportSeries<>("Target Status Overview", reportSeriesItems);
|
||||
@@ -117,25 +113,25 @@ public class JpaReportManagement implements ReportManagement {
|
||||
final List<DataReportSeriesItem<SeriesTime>> resultList = new ArrayList<>();
|
||||
|
||||
// hours
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.HOUR,
|
||||
resultList.add(new DataReportSeriesItem<>(SeriesTime.HOUR,
|
||||
entityManager.createQuery(createCountSelectTargetsLastPoll(cb, beforeHour, now)).getSingleResult()));
|
||||
// days
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.DAY, entityManager
|
||||
resultList.add(new DataReportSeriesItem<>(SeriesTime.DAY, entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeDay, beforeHour)).getSingleResult()));
|
||||
// weeks
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.WEEK, entityManager
|
||||
resultList.add(new DataReportSeriesItem<>(SeriesTime.WEEK, entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeWeek, beforeDay)).getSingleResult()));
|
||||
// months
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.MONTH, entityManager
|
||||
resultList.add(new DataReportSeriesItem<>(SeriesTime.MONTH, entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeMonth, beforeWeek)).getSingleResult()));
|
||||
// years
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.YEAR, entityManager
|
||||
resultList.add(new DataReportSeriesItem<>(SeriesTime.YEAR, entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeYear, beforeMonth)).getSingleResult()));
|
||||
// years
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.MORE_THAN_YEAR,
|
||||
resultList.add(new DataReportSeriesItem<>(SeriesTime.MORE_THAN_YEAR,
|
||||
entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, beforeYear)).getSingleResult()));
|
||||
// never
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.NEVER,
|
||||
resultList.add(new DataReportSeriesItem<>(SeriesTime.NEVER,
|
||||
entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, null)).getSingleResult()));
|
||||
|
||||
return new DataReportSeries<>("TargetLastPoll", resultList);
|
||||
@@ -172,8 +168,8 @@ public class JpaReportManagement implements ReportManagement {
|
||||
final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Object[]> queryTopX = cbTopX.createQuery(Object[].class);
|
||||
final Root<JpaDistributionSet> rootTopX = queryTopX.from(JpaDistributionSet.class);
|
||||
final ListJoin<JpaDistributionSet, JpaTargetInfo> joinTopX = rootTopX
|
||||
.join(JpaDistributionSet_.installedAtTargets, JoinType.LEFT);
|
||||
final ListJoin<JpaDistributionSet, JpaTarget> joinTopX = rootTopX.join(JpaDistributionSet_.installedAtTargets,
|
||||
JoinType.LEFT);
|
||||
final Expression<Long> countColumn = cbTopX.count(joinTopX);
|
||||
// top x usage query
|
||||
final CriteriaQuery<Object[]> groupBy = queryTopX
|
||||
@@ -270,14 +266,13 @@ public class JpaReportManagement implements ReportManagement {
|
||||
// count select statement
|
||||
final CriteriaQuery<Long> countSelect = cb.createQuery(Long.class);
|
||||
final Root<JpaTarget> countSelectRoot = countSelect.from(JpaTarget.class);
|
||||
final Join<JpaTarget, JpaTargetInfo> targetInfoJoin = countSelectRoot.join(JpaTarget_.targetInfo);
|
||||
countSelect.select(cb.count(countSelectRoot));
|
||||
if (start != null && end != null) {
|
||||
countSelect.where(cb.between(targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery), start, end));
|
||||
countSelect.where(cb.between(countSelectRoot.get(JpaTarget_.lastTargetQuery), start, end));
|
||||
} else if (from == null && to != null) {
|
||||
countSelect.where(cb.lessThanOrEqualTo(targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery), end));
|
||||
countSelect.where(cb.lessThanOrEqualTo(countSelectRoot.get(JpaTarget_.lastTargetQuery), end));
|
||||
} else {
|
||||
countSelect.where(cb.isNull(targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery)));
|
||||
countSelect.where(cb.isNull(countSelectRoot.get(JpaTarget_.lastTargetQuery)));
|
||||
}
|
||||
return countSelect;
|
||||
}
|
||||
@@ -314,10 +309,10 @@ public class JpaReportManagement implements ReportManagement {
|
||||
outerReportItems.add(outer.toItem());
|
||||
}
|
||||
} else {
|
||||
outerReportItems.add(new DataReportSeriesItem<String>("misc", inner.count));
|
||||
outerReportItems.add(new DataReportSeriesItem<>("misc", inner.count));
|
||||
}
|
||||
|
||||
innerOuterReport.add(new InnerOuterDataReportSeries<String>(
|
||||
innerOuterReport.add(new InnerOuterDataReportSeries<>(
|
||||
new DataReportSeries<>("DS-Name", Collections.singletonList(inner.toItem())),
|
||||
new DataReportSeries<>("DS-Version", outerReportItems)));
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
throw new RolloutIllegalStateException("First Group is not the first group.");
|
||||
}
|
||||
|
||||
deploymentManagement.startScheduledActionsByRolloutGroupParent(rollout, null);
|
||||
deploymentManagement.startScheduledActionsByRolloutGroupParent(rollout.getId(), null);
|
||||
|
||||
rolloutGroup.setStatus(RolloutGroupStatus.RUNNING);
|
||||
rolloutGroupRepository.save(rolloutGroup);
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
@@ -242,4 +243,9 @@ public class JpaTagManagement implements TagManagement {
|
||||
return convertDsPage(distributionSetTagRepository.findAll(spec, pageable), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TargetTag> findAllTargetTags(final Pageable pageable, final String controllerId) {
|
||||
return convertTPage(targetTagRepository.findAll(TagSpecification.ofTarget(controllerId), pageable), pageable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -20,8 +21,6 @@ import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -38,11 +37,8 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
@@ -99,9 +95,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Autowired
|
||||
private TargetTagRepository targetTagRepository;
|
||||
|
||||
@Autowired
|
||||
private TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
private NoCountPagingRepository criteriaNoCountDao;
|
||||
|
||||
@@ -122,28 +115,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return targetRepository.findByControllerId(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Target> findTargetByControllerIDWithDetails(final String controllerId) {
|
||||
final Optional<Target> result = targetRepository.findByControllerId(controllerId);
|
||||
// load lazy relations
|
||||
if (!result.isPresent()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result.get().getTargetInfo().getControllerAttributes().size();
|
||||
if (result.get().getTargetInfo() != null
|
||||
&& result.get().getTargetInfo().getInstalledDistributionSet() != null) {
|
||||
result.get().getTargetInfo().getInstalledDistributionSet().getName();
|
||||
result.get().getTargetInfo().getInstalledDistributionSet().getModules().size();
|
||||
}
|
||||
if (result.get().getAssignedDistributionSet() != null) {
|
||||
result.get().getAssignedDistributionSet().getName();
|
||||
result.get().getAssignedDistributionSet().getModules().size();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> findTargetByControllerID(final Collection<String> controllerIDs) {
|
||||
return Collections.unmodifiableList(targetRepository
|
||||
@@ -157,16 +128,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Slice<Target> findTargetsAll(final Pageable pageable) {
|
||||
// workarround - no join fetch allowed that is why we need specification
|
||||
// instead of query for
|
||||
// count() of Pageable
|
||||
final Specification<JpaTarget> spec = (root, query, cb) -> {
|
||||
if (!query.getResultType().isAssignableFrom(Long.class)) {
|
||||
root.fetch(JpaTarget_.targetInfo);
|
||||
}
|
||||
return cb.conjunction();
|
||||
};
|
||||
return convertPage(criteriaNoCountDao.findAll(spec, pageable, JpaTarget.class), pageable);
|
||||
return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,14 +150,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return convertPage(targetRepository.findAll(spec, pageable), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> findTargetsByControllerIDsWithTags(final List<String> controllerIDs) {
|
||||
final List<List<String>> partition = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT);
|
||||
return partition.stream()
|
||||
.map(ids -> targetRepository.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(ids)))
|
||||
.flatMap(t -> t.stream()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@@ -205,11 +159,9 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(update.getControllerId())
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, update.getControllerId()));
|
||||
|
||||
target.setNew(false);
|
||||
|
||||
update.getName().ifPresent(target::setName);
|
||||
update.getDescription().ifPresent(target::setDescription);
|
||||
update.getAddress().ifPresent(address -> ((JpaTargetInfo) target.getTargetInfo()).setAddress(address));
|
||||
update.getAddress().ifPresent(target::setAddress);
|
||||
update.getSecurityToken().ifPresent(target::setSecurityToken);
|
||||
|
||||
return targetRepository.save(target);
|
||||
@@ -282,7 +234,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Page<Target> findTargetByInstalledDistributionSet(final Long distributionSetID, final Pageable pageReq) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distributionSetID);
|
||||
return targetRepository.findByTargetInfoInstalledDistributionSetId(pageReq, distributionSetID);
|
||||
return targetRepository.findByInstalledDistributionSetId(pageReq, distributionSetID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -303,7 +255,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Page<Target> findTargetByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status) {
|
||||
return targetRepository.findByTargetInfoUpdateStatus(pageable, status);
|
||||
return targetRepository.findByUpdateStatus(pageable, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -312,8 +264,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final Boolean selectTargetWithNoTag, final String... tagNames) {
|
||||
final List<Specification<JpaTarget>> specList = buildSpecificationList(
|
||||
new FilterParams(installedOrAssignedDistributionSetId, status, overdueState, searchText,
|
||||
selectTargetWithNoTag, tagNames),
|
||||
true);
|
||||
selectTargetWithNoTag, tagNames));
|
||||
return findByCriteriaAPI(pageable, specList);
|
||||
}
|
||||
|
||||
@@ -323,16 +274,14 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final Boolean selectTargetWithNoTag, final String... tagNames) {
|
||||
final List<Specification<JpaTarget>> specList = buildSpecificationList(
|
||||
new FilterParams(installedOrAssignedDistributionSetId, status, overdueState, searchText,
|
||||
selectTargetWithNoTag, tagNames),
|
||||
true);
|
||||
selectTargetWithNoTag, tagNames));
|
||||
return countByCriteriaAPI(specList);
|
||||
}
|
||||
|
||||
private List<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams,
|
||||
final boolean fetch) {
|
||||
private List<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams) {
|
||||
final List<Specification<JpaTarget>> specList = new ArrayList<>();
|
||||
if (filterParams.getFilterByStatus() != null && !filterParams.getFilterByStatus().isEmpty()) {
|
||||
specList.add(TargetSpecifications.hasTargetUpdateStatus(filterParams.getFilterByStatus(), fetch));
|
||||
specList.add(TargetSpecifications.hasTargetUpdateStatus(filterParams.getFilterByStatus()));
|
||||
}
|
||||
if (filterParams.getOverdueState() != null) {
|
||||
specList.add(TargetSpecifications.isOverdue(TimestampCalculator.calculateOverdueTimestamp()));
|
||||
@@ -470,15 +419,11 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final CriteriaQuery<JpaTarget> query = cb.createQuery(JpaTarget.class);
|
||||
final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);
|
||||
|
||||
// necessary joins for the select
|
||||
final Join<JpaTarget, JpaTargetInfo> targetInfo = (Join<JpaTarget, JpaTargetInfo>) targetRoot
|
||||
.fetch(JpaTarget_.targetInfo, JoinType.LEFT);
|
||||
|
||||
// select case expression to retrieve the case value as a column to be
|
||||
// able to order based on
|
||||
// this column, installed first,...
|
||||
final Expression<Object> selectCase = cb.selectCase()
|
||||
.when(cb.equal(targetInfo.get(JpaTargetInfo_.installedDistributionSet).get(JpaDistributionSet_.id),
|
||||
.when(cb.equal(targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id),
|
||||
orderByDistributionId), 1)
|
||||
.when(cb.equal(targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id),
|
||||
orderByDistributionId), 2)
|
||||
@@ -487,8 +432,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
query.distinct(true);
|
||||
// build the specifications and then to predicates necessary by the
|
||||
// given filters
|
||||
final Predicate[] specificationsForMultiSelect = specificationsToPredicate(
|
||||
buildSpecificationList(filterParams, true), targetRoot, query, cb);
|
||||
final Predicate[] specificationsForMultiSelect = specificationsToPredicate(buildSpecificationList(filterParams),
|
||||
targetRoot, query, cb);
|
||||
|
||||
// if we have some predicates then add it to the where clause of the
|
||||
// multiselect
|
||||
@@ -532,7 +477,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Long countTargetByInstalledDistributionSet(final Long distId) {
|
||||
throwEntityNotFoundIfDsDoesNotExist(distId);
|
||||
|
||||
return targetRepository.countByTargetInfoInstalledDistributionSetId(distId);
|
||||
return targetRepository.countByInstalledDistributionSetId(distId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -611,14 +556,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
throw new EntityAlreadyExistsException();
|
||||
}
|
||||
|
||||
target.setNew(true);
|
||||
final JpaTarget savedTarget = targetRepository.save(target);
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) savedTarget.getTargetInfo();
|
||||
|
||||
targetInfo.setNew(true);
|
||||
final Target targetToReturn = targetInfoRepository.save(targetInfo).getTarget();
|
||||
targetInfo.setNew(false);
|
||||
return targetToReturn;
|
||||
return targetRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -668,4 +606,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return Collections.unmodifiableList(targetRepository.findAll(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getControllerAttributes(final String controllerId) {
|
||||
final JpaTarget target = (JpaTarget) findTargetByControllerID(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
return target.getControllerAttributes();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Usually a JPA spring data repository to handle {@link TargetInfo} entity.
|
||||
* However, do to an eclipselink bug with spring boot now a regular interface
|
||||
* that is implemented by {@link EclipseLinkTargetInfoRepository}.
|
||||
*
|
||||
*/
|
||||
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
|
||||
public interface TargetInfoRepository {
|
||||
|
||||
/**
|
||||
* Sets new TargetUpdateStatus of given target if is not already on that
|
||||
* value.
|
||||
*
|
||||
* @param status
|
||||
* to set
|
||||
* @param targets
|
||||
* to set it for
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Query("update JpaTargetInfo ti set ti.updateStatus = :status where ti.targetId in :targets and ti.updateStatus != :status")
|
||||
void setTargetUpdateStatus(@Param("status") TargetUpdateStatus status, @Param("targets") List<Long> targets);
|
||||
|
||||
/**
|
||||
* Save entity and evict cache with it.
|
||||
*
|
||||
* @param entity
|
||||
* to persists
|
||||
*
|
||||
* @return persisted or updated {@link Entity}
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
<S extends JpaTargetInfo> S save(S entity);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
@@ -17,12 +18,9 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@@ -38,19 +36,43 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>, JpaSpecificationExecutor<JpaTarget> {
|
||||
|
||||
/**
|
||||
* Loads {@link Target} including details {@link EntityGraph} by given ID.
|
||||
* Sets {@link JpaTarget#getAssignedDistributionSet()}.
|
||||
*
|
||||
* @param set
|
||||
* to use
|
||||
* @param status
|
||||
* to set
|
||||
* @param modifiedAt
|
||||
* current time
|
||||
* @param modifiedBy
|
||||
* current auditor
|
||||
* @param targets
|
||||
* to update
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :set, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy, t.updateStatus = :status WHERE t.id IN :targets")
|
||||
void setAssignedDistributionSetAndUpdateStatus(@Param("status") TargetUpdateStatus status,
|
||||
@Param("set") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt,
|
||||
@Param("lastModifiedBy") String modifiedBy, @Param("targets") Collection<Long> targets);
|
||||
|
||||
/**
|
||||
* Loads {@link Target} by given ID.
|
||||
*
|
||||
* @param controllerID
|
||||
* to search for
|
||||
* @return found {@link Target} or <code>null</code> if not found.
|
||||
*/
|
||||
@EntityGraph(value = "Target.detail", type = EntityGraphType.LOAD)
|
||||
Optional<Target> findByControllerId(String controllerID);
|
||||
|
||||
@Query("SELECT t.controllerAttributes FROM JpaTarget t WHERE t.controllerId=:controllerId")
|
||||
Map<String, String> getControllerAttributes(@Param("controllerId") String controllerId);
|
||||
|
||||
/**
|
||||
* Checks if target with given id exists.
|
||||
*
|
||||
* @param controllerId to check
|
||||
* @param controllerId
|
||||
* to check
|
||||
* @return <code>true</code> if target with given id exists
|
||||
*/
|
||||
@Query("SELECT CASE WHEN COUNT(t)>0 THEN 'true' ELSE 'false' END FROM JpaTarget t WHERE t.controllerId=:controllerId")
|
||||
@@ -102,7 +124,7 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
*
|
||||
* @return found targets
|
||||
*/
|
||||
Page<Target> findByTargetInfoUpdateStatus(final Pageable pageable, final TargetUpdateStatus status);
|
||||
Page<Target> findByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status);
|
||||
|
||||
/**
|
||||
* retrieves the {@link Target}s which has the {@link DistributionSet}
|
||||
@@ -114,7 +136,7 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
* the ID of the {@link DistributionSet}
|
||||
* @return the found {@link Target}s
|
||||
*/
|
||||
Page<Target> findByTargetInfoInstalledDistributionSetId(final Pageable pageable, final Long setID);
|
||||
Page<Target> findByInstalledDistributionSetId(final Pageable pageable, final Long setID);
|
||||
|
||||
/**
|
||||
* Finds all targets that have defined {@link DistributionSet} assigned.
|
||||
@@ -141,13 +163,13 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
|
||||
/**
|
||||
* Counts number of targets with given
|
||||
* {@link TargetInfo#getInstalledDistributionSet()}.
|
||||
* {@link Target#getInstalledDistributionSet()}.
|
||||
*
|
||||
* @param distId
|
||||
* to search for
|
||||
* @return number of found {@link Target}s.
|
||||
*/
|
||||
Long countByTargetInfoInstalledDistributionSetId(final Long distId);
|
||||
Long countByInstalledDistributionSetId(final Long distId);
|
||||
|
||||
/**
|
||||
* Finds all {@link Target}s in the repository.
|
||||
@@ -164,24 +186,6 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
@Query("SELECT t FROM JpaTarget t WHERE t.id IN ?1")
|
||||
List<JpaTarget> findAll(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
* Sets {@link Target#getAssignedDistributionSet()}.
|
||||
*
|
||||
* @param set
|
||||
* to use
|
||||
* @param modifiedAt
|
||||
* current time
|
||||
* @param modifiedBy
|
||||
* current auditor
|
||||
* @param targets
|
||||
* to update
|
||||
*/
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :set, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy WHERE t.id IN :targets")
|
||||
void setAssignedDistributionSet(@Param("set") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt,
|
||||
@Param("lastModifiedBy") String modifiedBy, @Param("targets") Collection<Long> targets);
|
||||
|
||||
/**
|
||||
*
|
||||
* Finds all targets of a rollout group.
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractTargetUpdateCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
/**
|
||||
@@ -40,11 +39,9 @@ public class JpaTargetCreate extends AbstractTargetUpdateCreate<TargetCreate> im
|
||||
}
|
||||
|
||||
target.setDescription(description);
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) target.getTargetInfo();
|
||||
|
||||
targetInfo.setAddress(address);
|
||||
targetInfo.setUpdateStatus(getStatus().orElse(TargetUpdateStatus.UNKNOWN));
|
||||
getLastTargetQuery().ifPresent(targetInfo::setLastTargetQuery);
|
||||
target.setAddress(address);
|
||||
target.setUpdateStatus(getStatus().orElse(TargetUpdateStatus.UNKNOWN));
|
||||
getLastTargetQuery().ifPresent(target::setLastTargetQuery);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -18,12 +18,14 @@ import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
/**
|
||||
* Holder of the base attributes common to all entities.
|
||||
@@ -72,26 +74,26 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
|
||||
|
||||
@Override
|
||||
@Access(AccessType.PROPERTY)
|
||||
@Column(name = "last_modified_at", insertable = false, updatable = true)
|
||||
@Column(name = "last_modified_at", insertable = true, updatable = true)
|
||||
public Long getLastModifiedAt() {
|
||||
return lastModifiedAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Access(AccessType.PROPERTY)
|
||||
@Column(name = "last_modified_by", insertable = false, updatable = true, length = 40)
|
||||
@Column(name = "last_modified_by", insertable = true, updatable = true, length = 40)
|
||||
public String getLastModifiedBy() {
|
||||
return lastModifiedBy;
|
||||
}
|
||||
|
||||
@CreatedBy
|
||||
public void setCreatedBy(final String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
if (isController()) {
|
||||
this.createdBy = "CONTROLLER_PLUG_AND_PLAY";
|
||||
return;
|
||||
}
|
||||
|
||||
@LastModifiedBy
|
||||
public void setLastModifiedBy(final String lastModifiedBy) {
|
||||
this.lastModifiedBy = lastModifiedBy;
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
@CreatedDate
|
||||
@@ -101,9 +103,30 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
|
||||
|
||||
@LastModifiedDate
|
||||
public void setLastModifiedAt(final Long lastModifiedAt) {
|
||||
|
||||
if (isController()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.lastModifiedAt = lastModifiedAt;
|
||||
}
|
||||
|
||||
@LastModifiedBy
|
||||
public void setLastModifiedBy(final String lastModifiedBy) {
|
||||
if (isController()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.lastModifiedBy = lastModifiedBy;
|
||||
}
|
||||
|
||||
private boolean isController() {
|
||||
return SecurityContextHolder.getContext().getAuthentication()
|
||||
.getDetails() instanceof TenantAwareAuthenticationDetails
|
||||
&& ((TenantAwareAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication()
|
||||
.getDetails()).isController();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOptLockRevision() {
|
||||
return optLockRevision;
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEventAdapter;
|
||||
import org.eclipse.persistence.queries.UpdateObjectQuery;
|
||||
|
||||
/**
|
||||
* Listens to change in property values of an entity and calls the corresponding
|
||||
@@ -29,10 +30,13 @@ public class EntityPropertyChangeListener extends DescriptorEventAdapter {
|
||||
|
||||
@Override
|
||||
public void postUpdate(final DescriptorEvent event) {
|
||||
|
||||
final Object object = event.getObject();
|
||||
if (isEventAwareEntity(object)) {
|
||||
if (isEventAwareEntity(object)
|
||||
&& isFireUpdate((EventAwareEntity) object, (UpdateObjectQuery) event.getQuery())) {
|
||||
doNotifiy(() -> ((EventAwareEntity) object).fireUpdateEvent(event));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,4 +55,9 @@ public class EntityPropertyChangeListener extends DescriptorEventAdapter {
|
||||
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(runnable);
|
||||
}
|
||||
|
||||
private static boolean isFireUpdate(final EventAwareEntity entity, final UpdateObjectQuery query) {
|
||||
return entity.getUpdateIgnoreFields().isEmpty() || query.getObjectChangeSet().getChangedAttributeNames()
|
||||
.stream().anyMatch(field -> !entity.getUpdateIgnoreFields().contains(field));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
|
||||
/**
|
||||
@@ -36,4 +39,12 @@ public interface EventAwareEntity {
|
||||
* @param descriptorEvent
|
||||
*/
|
||||
void fireDeleteEvent(DescriptorEvent descriptorEvent);
|
||||
|
||||
/**
|
||||
* @return list of entity fields that if the only changed fields prevents
|
||||
* {@link #fireUpdateEvent(DescriptorEvent)} call.
|
||||
*/
|
||||
default List<String> getUpdateIgnoreFields() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
@OneToMany(mappedBy = "autoAssignDistributionSet", targetEntity = JpaTargetFilterQuery.class, fetch = FetchType.LAZY)
|
||||
private List<TargetFilterQuery> autoAssignFilters;
|
||||
|
||||
@OneToMany(mappedBy = "installedDistributionSet", targetEntity = JpaTargetInfo.class, fetch = FetchType.LAZY)
|
||||
private List<JpaTargetInfo> installedAtTargets;
|
||||
@OneToMany(mappedBy = "installedDistributionSet", targetEntity = JpaTarget.class, fetch = FetchType.LAZY)
|
||||
private List<JpaTarget> installedAtTargets;
|
||||
|
||||
@OneToMany(mappedBy = "distributionSet", targetEntity = JpaAction.class, fetch = FetchType.LAZY)
|
||||
private List<JpaAction> actions;
|
||||
|
||||
@@ -8,16 +8,27 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.Index;
|
||||
@@ -25,14 +36,11 @@ import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@@ -45,14 +53,21 @@ import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHol
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.PollStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.eclipse.persistence.annotations.CascadeOnDelete;
|
||||
import org.eclipse.persistence.descriptors.DescriptorEvent;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.data.domain.Persistable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* JPA implementation of {@link Target}.
|
||||
@@ -64,26 +79,27 @@ import org.springframework.data.domain.Persistable;
|
||||
@Index(name = "sp_idx_target_02", columnList = "tenant,name"),
|
||||
@Index(name = "sp_idx_target_03", columnList = "tenant,controller_id,assigned_distribution_set"),
|
||||
@Index(name = "sp_idx_target_04", columnList = "tenant,created_at"),
|
||||
@Index(name = "sp_idx_target_05", columnList = "tenant,address"),
|
||||
@Index(name = "sp_idx_target_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = {
|
||||
"controller_id", "tenant" }, name = "uk_tenant_controller_id"))
|
||||
@NamedEntityGraph(name = "Target.detail", attributeNodes = { @NamedAttributeNode("tags"),
|
||||
@NamedAttributeNode(value = "assignedDistributionSet"), @NamedAttributeNode(value = "targetInfo") })
|
||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
|
||||
// sub entities
|
||||
@SuppressWarnings("squid:S2160")
|
||||
public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Long>, Target, EventAwareEntity {
|
||||
public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAwareEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JpaTarget.class);
|
||||
|
||||
private static final List<String> TARGET_UPDATE_EVENT_IGNORE_FIELDS = Lists.newArrayList("lastTargetQuery",
|
||||
"lastTargetQuery", "address", "optLockRevision", "lastModifiedAt", "lastModifiedBy");
|
||||
|
||||
@Column(name = "controller_id", length = 64)
|
||||
@Size(min = 1, max = 64)
|
||||
@NotEmpty
|
||||
@Pattern(regexp = "[.\\S]*", message = "has whitespaces which are not allowed")
|
||||
private String controllerId;
|
||||
|
||||
@Transient
|
||||
private boolean entityNew;
|
||||
|
||||
@CascadeOnDelete
|
||||
@ManyToMany(targetEntity = JpaTargetTag.class)
|
||||
@JoinTable(name = "sp_target_target_tag", joinColumns = {
|
||||
@@ -95,16 +111,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
|
||||
@OneToMany(mappedBy = "target", fetch = FetchType.LAZY, targetEntity = JpaAction.class)
|
||||
private List<JpaAction> actions;
|
||||
|
||||
@ManyToOne(optional = true, fetch = FetchType.LAZY, targetEntity = JpaDistributionSet.class)
|
||||
@JoinColumn(name = "assigned_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_assign_ds"))
|
||||
private JpaDistributionSet assignedDistributionSet;
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToOne(cascade = { CascadeType.PERSIST,
|
||||
CascadeType.MERGE }, fetch = FetchType.LAZY, targetEntity = JpaTargetInfo.class)
|
||||
@PrimaryKeyJoinColumn
|
||||
private JpaTargetInfo targetInfo;
|
||||
|
||||
/**
|
||||
* the security token of the target which allows if enabled to authenticate
|
||||
* with this security token.
|
||||
@@ -118,6 +124,46 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
|
||||
@OneToMany(mappedBy = "target", fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST })
|
||||
private List<RolloutTargetGroup> rolloutTargetGroup;
|
||||
|
||||
@Column(name = "address", length = 512)
|
||||
@Size(max = 512)
|
||||
private String address;
|
||||
|
||||
@Column(name = "last_target_query")
|
||||
private Long lastTargetQuery;
|
||||
|
||||
@Column(name = "install_date")
|
||||
private Long installationDate;
|
||||
|
||||
@Column(name = "update_status", nullable = false, length = 16)
|
||||
@Enumerated(EnumType.STRING)
|
||||
@NotNull
|
||||
private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN;
|
||||
|
||||
@ManyToOne(optional = true, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "installed_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_inst_ds"))
|
||||
private JpaDistributionSet installedDistributionSet;
|
||||
|
||||
@ManyToOne(optional = true, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "assigned_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_assign_ds"))
|
||||
private JpaDistributionSet assignedDistributionSet;
|
||||
|
||||
/**
|
||||
* Read only on management API. Are committed by controller.
|
||||
*/
|
||||
@CascadeOnDelete
|
||||
@ElementCollection
|
||||
@Column(name = "attribute_value", length = 128)
|
||||
@MapKeyColumn(name = "attribute_key", nullable = false, length = 32)
|
||||
@CollectionTable(name = "sp_target_attributes", joinColumns = {
|
||||
@JoinColumn(name = "target_id", nullable = false, updatable = false) }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target"))
|
||||
private final Map<String, String> controllerAttributes = Collections.synchronizedMap(new HashMap<String, String>());
|
||||
|
||||
// set default request controller attributes to true, because we want to
|
||||
// request them the first
|
||||
// time
|
||||
@Column(name = "request_controller_attributes", nullable = false)
|
||||
private boolean requestControllerAttributes = true;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -140,14 +186,12 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
|
||||
this.controllerId = controllerId;
|
||||
setName(controllerId);
|
||||
this.securityToken = securityToken;
|
||||
targetInfo = new JpaTargetInfo(this);
|
||||
}
|
||||
|
||||
JpaTarget() {
|
||||
// empty constructor for JPA.
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSet getAssignedDistributionSet() {
|
||||
return assignedDistributionSet;
|
||||
}
|
||||
@@ -157,7 +201,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
|
||||
return controllerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TargetTag> getTags() {
|
||||
if (tags == null) {
|
||||
return Collections.emptySet();
|
||||
@@ -198,7 +241,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
|
||||
this.controllerId = controllerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Action> getActions() {
|
||||
if (actions == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -215,36 +257,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
|
||||
return actions.add((JpaAction) action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isNew() {
|
||||
return entityNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entityNew
|
||||
* the isNew to set
|
||||
*/
|
||||
public void setNew(final boolean entityNew) {
|
||||
this.entityNew = entityNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the targetInfo
|
||||
*/
|
||||
@Override
|
||||
public TargetInfo getTargetInfo() {
|
||||
return targetInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param targetInfo
|
||||
* the targetInfo to set
|
||||
*/
|
||||
public void setTargetInfo(final TargetInfo targetInfo) {
|
||||
this.targetInfo = (JpaTargetInfo) targetInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the securityToken if the current security context contains the
|
||||
* necessary permission {@link SpPermission#READ_TARGET_SEC_TOKEN}
|
||||
@@ -260,17 +272,110 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param securityToken
|
||||
* the securityToken to set
|
||||
*/
|
||||
public void setSecurityToken(final String securityToken) {
|
||||
this.securityToken = securityToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ipAddress
|
||||
*/
|
||||
@Override
|
||||
public URI getAddress() {
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return URI.create(address);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
LOG.warn("Invalid address provided. Cloud not be configured to URI", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the poll time which holds the last poll time of the target, the
|
||||
* next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled
|
||||
* before this method returns {@code null}
|
||||
*/
|
||||
@Override
|
||||
public PollStatus getPollStatus() {
|
||||
if (lastTargetQuery == null) {
|
||||
return null;
|
||||
}
|
||||
return SystemSecurityContextHolder.getInstance().getSystemSecurityContext().runAsSystem(() -> {
|
||||
final Duration pollTime = DurationHelper.formattedStringToDuration(TenantConfigurationManagementHolder
|
||||
.getInstance().getTenantConfigurationManagement()
|
||||
.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class).getValue());
|
||||
final Duration overdueTime = DurationHelper.formattedStringToDuration(
|
||||
TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement()
|
||||
.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class)
|
||||
.getValue());
|
||||
final LocalDateTime currentDate = LocalDateTime.now();
|
||||
final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery),
|
||||
ZoneId.systemDefault());
|
||||
final LocalDateTime nextPollDate = lastPollDate.plus(pollTime);
|
||||
final LocalDateTime overdueDate = nextPollDate.plus(overdueTime);
|
||||
return new PollStatus(lastPollDate, nextPollDate, overdueDate, currentDate);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getLastTargetQuery() {
|
||||
return lastTargetQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getInstallationDate() {
|
||||
return installationDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetUpdateStatus getUpdateStatus() {
|
||||
return updateStatus;
|
||||
}
|
||||
|
||||
public JpaDistributionSet getInstalledDistributionSet() {
|
||||
return installedDistributionSet;
|
||||
}
|
||||
|
||||
public Map<String, String> getControllerAttributes() {
|
||||
return controllerAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRequestControllerAttributes() {
|
||||
return requestControllerAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Target [controllerId=" + controllerId + ", getId()=" + getId() + "]";
|
||||
return "JpaTarget [controllerId=" + controllerId + ", revision=" + getOptLockRevision() + ", id=" + getId()
|
||||
+ "]";
|
||||
}
|
||||
|
||||
public void setAddress(final String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setLastTargetQuery(final Long lastTargetQuery) {
|
||||
this.lastTargetQuery = lastTargetQuery;
|
||||
}
|
||||
|
||||
public void setInstallationDate(final Long installationDate) {
|
||||
this.installationDate = installationDate;
|
||||
}
|
||||
|
||||
public void setInstalledDistributionSet(final JpaDistributionSet installedDistributionSet) {
|
||||
this.installedDistributionSet = installedDistributionSet;
|
||||
}
|
||||
|
||||
public void setUpdateStatus(final TargetUpdateStatus updateStatus) {
|
||||
this.updateStatus = updateStatus;
|
||||
}
|
||||
|
||||
public void setRequestControllerAttributes(final boolean requestControllerAttributes) {
|
||||
this.requestControllerAttributes = requestControllerAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -279,6 +384,11 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
|
||||
.publishEvent(new TargetCreatedEvent(this, EventPublisherHolder.getInstance().getApplicationId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUpdateIgnoreFields() {
|
||||
return TARGET_UPDATE_EVENT_IGNORE_FIELDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
|
||||
EventPublisherHolder.getInstance().getEventPublisher()
|
||||
|
||||
@@ -1,310 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.MapsId;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.PollStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.eclipse.persistence.annotations.CascadeOnDelete;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Persistable;
|
||||
|
||||
/**
|
||||
* A table which contains all the information inserted, updated by the
|
||||
* controller itself. So this entity does not provide audit information because
|
||||
* changes on this entity are mostly only done by controller requests. That's
|
||||
* the reason that we store these information in a separated table so we don't
|
||||
* modifying the {@link Target} itself when a controller reports it's
|
||||
* {@link #lastTargetQuery} for example.
|
||||
*
|
||||
*/
|
||||
@Table(name = "sp_target_info", indexes = {
|
||||
@Index(name = "sp_idx_target_info_02", columnList = "target_id,update_status") })
|
||||
@Entity
|
||||
@EntityListeners(EntityPropertyChangeListener.class)
|
||||
public class JpaTargetInfo implements Persistable<Long>, TargetInfo {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TargetInfo.class);
|
||||
|
||||
@Id
|
||||
private Long targetId;
|
||||
|
||||
@Transient
|
||||
private boolean entityNew;
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, targetEntity = JpaTarget.class)
|
||||
@JoinColumn(name = "target_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_stat_targ"))
|
||||
@MapsId
|
||||
private JpaTarget target;
|
||||
|
||||
@Column(name = "address", length = 512)
|
||||
@Size(max = 512)
|
||||
private String address;
|
||||
|
||||
@Column(name = "last_target_query")
|
||||
private Long lastTargetQuery;
|
||||
|
||||
@Column(name = "install_date")
|
||||
private Long installationDate;
|
||||
|
||||
@Column(name = "update_status", nullable = false, length = 16)
|
||||
@Enumerated(EnumType.STRING)
|
||||
@NotNull
|
||||
private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN;
|
||||
|
||||
@ManyToOne(optional = true, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "installed_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_inst_ds"))
|
||||
private JpaDistributionSet installedDistributionSet;
|
||||
|
||||
/**
|
||||
* Read only on management API. Are commited by controller.
|
||||
*/
|
||||
@CascadeOnDelete
|
||||
@ElementCollection
|
||||
@Column(name = "attribute_value", length = 128)
|
||||
@MapKeyColumn(name = "attribute_key", nullable = false, length = 32)
|
||||
@CollectionTable(name = "sp_target_attributes", joinColumns = {
|
||||
@JoinColumn(name = "target_id", nullable = false, updatable = false) }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target"))
|
||||
private final Map<String, String> controllerAttributes = Collections.synchronizedMap(new HashMap<String, String>());
|
||||
|
||||
// set default request controller attributes to true, because we want to
|
||||
// request them the first
|
||||
// time
|
||||
@Column(name = "request_controller_attributes", nullable = false)
|
||||
private boolean requestControllerAttributes = true;
|
||||
|
||||
/**
|
||||
* Constructor for {@link JpaTargetInfo}.
|
||||
*
|
||||
* @param target
|
||||
* related to this status.
|
||||
*/
|
||||
public JpaTargetInfo(final JpaTarget target) {
|
||||
this.target = target;
|
||||
targetId = target.getId();
|
||||
}
|
||||
|
||||
JpaTargetInfo() {
|
||||
target = null;
|
||||
targetId = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isNew() {
|
||||
return entityNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entityNew
|
||||
* the isNew to set
|
||||
*/
|
||||
public void setNew(final boolean entityNew) {
|
||||
this.entityNew = entityNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ipAddress
|
||||
*/
|
||||
@Override
|
||||
public URI getAddress() {
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return URI.create(address);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
LOG.warn("Invalid address provided. Cloud not be configured to URI", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAddress(final String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Long getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
public void setTargetId(final Long targetId) {
|
||||
this.targetId = targetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(final JpaTarget target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getLastTargetQuery() {
|
||||
return lastTargetQuery;
|
||||
}
|
||||
|
||||
public void setLastTargetQuery(final long lastTargetQuery) {
|
||||
this.lastTargetQuery = lastTargetQuery;
|
||||
}
|
||||
|
||||
public void setRequestControllerAttributes(final boolean requestControllerAttributes) {
|
||||
this.requestControllerAttributes = requestControllerAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getControllerAttributes() {
|
||||
return controllerAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRequestControllerAttributes() {
|
||||
return requestControllerAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getInstallationDate() {
|
||||
return installationDate;
|
||||
}
|
||||
|
||||
public void setInstallationDate(final Long installationDate) {
|
||||
this.installationDate = installationDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetUpdateStatus getUpdateStatus() {
|
||||
return updateStatus;
|
||||
}
|
||||
|
||||
public void setUpdateStatus(final TargetUpdateStatus updateStatus) {
|
||||
this.updateStatus = updateStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSet getInstalledDistributionSet() {
|
||||
return installedDistributionSet;
|
||||
}
|
||||
|
||||
public void setInstalledDistributionSet(final JpaDistributionSet installedDistributionSet) {
|
||||
this.installedDistributionSet = installedDistributionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the poll time which holds the last poll time of the target, the
|
||||
* next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled
|
||||
* before this method returns {@code null}
|
||||
*/
|
||||
@Override
|
||||
public PollStatus getPollStatus() {
|
||||
if (lastTargetQuery == null) {
|
||||
return null;
|
||||
}
|
||||
return SystemSecurityContextHolder.getInstance().getSystemSecurityContext().runAsSystem(() -> {
|
||||
final Duration pollTime = DurationHelper.formattedStringToDuration(TenantConfigurationManagementHolder
|
||||
.getInstance().getTenantConfigurationManagement()
|
||||
.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class).getValue());
|
||||
final Duration overdueTime = DurationHelper.formattedStringToDuration(
|
||||
TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement()
|
||||
.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class)
|
||||
.getValue());
|
||||
final LocalDateTime currentDate = LocalDateTime.now();
|
||||
final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery),
|
||||
ZoneId.systemDefault());
|
||||
final LocalDateTime nextPollDate = lastPollDate.plus(pollTime);
|
||||
final LocalDateTime overdueDate = nextPollDate.plus(overdueTime);
|
||||
return new PollStatus(lastPollDate, nextPollDate, overdueDate, currentDate);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((target == null) ? 0 : target.hashCode());
|
||||
result = prime * result + ((targetId == null) ? 0 : targetId.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof TargetInfo)) {
|
||||
return false;
|
||||
}
|
||||
final JpaTargetInfo other = (JpaTargetInfo) obj;
|
||||
if (target == null) {
|
||||
if (other.target != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!target.equals(other.target)) {
|
||||
return false;
|
||||
}
|
||||
if (targetId == null) {
|
||||
if (other.targetId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!targetId.equals(other.targetId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -56,8 +56,8 @@ public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActi
|
||||
// retrieve all actions according to the parent group of the finished
|
||||
// rolloutGroup, so retrieve all child-group actions which need to be
|
||||
// started.
|
||||
final long countOfStartedActions = deploymentManagement.startScheduledActionsByRolloutGroupParent(rollout,
|
||||
rolloutGroup);
|
||||
final long countOfStartedActions = deploymentManagement
|
||||
.startScheduledActionsByRolloutGroupParent(rollout.getId(), rolloutGroup.getId());
|
||||
logger.debug("{} Next actions started for rollout {} and parent group {}", countOfStartedActions, rollout,
|
||||
rolloutGroup);
|
||||
if (countOfStartedActions > 0) {
|
||||
|
||||
@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.ListJoin;
|
||||
import javax.persistence.criteria.Path;
|
||||
@@ -24,8 +23,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
@@ -200,10 +197,9 @@ public final class DistributionSetSpecification {
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> installedTarget(final String installedTargetId) {
|
||||
return (dsRoot, query, cb) -> {
|
||||
final ListJoin<JpaDistributionSet, JpaTargetInfo> installedTargetJoin = dsRoot
|
||||
final ListJoin<JpaDistributionSet, JpaTarget> installedTargetJoin = dsRoot
|
||||
.join(JpaDistributionSet_.installedAtTargets, JoinType.INNER);
|
||||
final Join<JpaTargetInfo, JpaTarget> targetJoin = installedTargetJoin.join(JpaTargetInfo_.target);
|
||||
return cb.equal(targetJoin.get(JpaTarget_.controllerId), installedTargetId);
|
||||
return cb.equal(installedTargetJoin.get(JpaTarget_.controllerId), installedTargetId);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||
|
||||
import javax.persistence.criteria.Join;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
/**
|
||||
* Specifications class for {@link Tag}s. The class provides Spring Data JPQL
|
||||
* Specifications.
|
||||
*
|
||||
*/
|
||||
public final class TagSpecification {
|
||||
private TagSpecification() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by its
|
||||
* DELETED attribute.
|
||||
*
|
||||
* @param isDeleted
|
||||
* TRUE/FALSE are compared to the attribute DELETED. If NULL the
|
||||
* attribute is ignored
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTargetTag> ofTarget(final String controllerId) {
|
||||
return (targetRoot, query, criteriaBuilder) -> {
|
||||
final Join<JpaTargetTag, JpaTarget> tagJoin = targetRoot.join(JpaTargetTag_.assignedToTargets);
|
||||
|
||||
query.distinct(true);
|
||||
|
||||
return criteriaBuilder.equal(tagJoin.get(JpaTarget_.controllerId), controllerId);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.ListJoin;
|
||||
import javax.persistence.criteria.Path;
|
||||
@@ -27,8 +26,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
@@ -37,7 +34,6 @@ import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup_;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
@@ -101,20 +97,8 @@ public final class TargetSpecifications {
|
||||
* join it.
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> hasTargetUpdateStatus(final Collection<TargetUpdateStatus> updateStatus,
|
||||
final boolean fetch) {
|
||||
return (targetRoot, query, cb) -> {
|
||||
if (!query.getResultType().isAssignableFrom(Long.class)) {
|
||||
if (fetch) {
|
||||
targetRoot.fetch(JpaTarget_.targetInfo);
|
||||
} else {
|
||||
targetRoot.join(JpaTarget_.targetInfo);
|
||||
}
|
||||
return targetRoot.get(JpaTarget_.targetInfo).get(JpaTargetInfo_.updateStatus).in(updateStatus);
|
||||
}
|
||||
final Join<JpaTarget, JpaTargetInfo> targetInfoJoin = targetRoot.join(JpaTarget_.targetInfo);
|
||||
return targetInfoJoin.get(JpaTargetInfo_.updateStatus).in(updateStatus);
|
||||
};
|
||||
public static Specification<JpaTarget> hasTargetUpdateStatus(final Collection<TargetUpdateStatus> updateStatus) {
|
||||
return (targetRoot, query, cb) -> targetRoot.get(JpaTarget_.updateStatus).in(updateStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,10 +118,8 @@ public final class TargetSpecifications {
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> isOverdue(final long overdueTimestamp) {
|
||||
return (targetRoot, query, cb) -> {
|
||||
final Join<JpaTarget, JpaTargetInfo> targetInfoJoin = targetRoot.join(JpaTarget_.targetInfo);
|
||||
return cb.lessThanOrEqualTo(targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery), overdueTimestamp);
|
||||
};
|
||||
return (targetRoot, query, cb) -> cb.lessThanOrEqualTo(targetRoot.get(JpaTarget_.lastTargetQuery),
|
||||
overdueTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,14 +148,11 @@ public final class TargetSpecifications {
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> hasInstalledOrAssignedDistributionSet(@NotNull final Long distributionId) {
|
||||
return (targetRoot, query, cb) -> {
|
||||
final Join<JpaTarget, JpaTargetInfo> targetInfoJoin = targetRoot.join(JpaTarget_.targetInfo);
|
||||
return cb.or(
|
||||
cb.equal(targetInfoJoin.get(JpaTargetInfo_.installedDistributionSet).get(JpaDistributionSet_.id),
|
||||
distributionId),
|
||||
cb.equal(targetRoot.<JpaDistributionSet> get(JpaTarget_.assignedDistributionSet)
|
||||
.get(JpaDistributionSet_.id), distributionId));
|
||||
};
|
||||
return (targetRoot, query, cb) -> cb.or(
|
||||
cb.equal(targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id),
|
||||
distributionId),
|
||||
cb.equal(targetRoot.<JpaDistributionSet> get(JpaTarget_.assignedDistributionSet)
|
||||
.get(JpaDistributionSet_.id), distributionId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,10 +288,7 @@ public final class TargetSpecifications {
|
||||
* @return the {@link Target} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaTarget> hasInstalledDistributionSet(final Long distributionSetId) {
|
||||
return (targetRoot, query, cb) -> {
|
||||
final Join<JpaTarget, JpaTargetInfo> targetInfoJoin = targetRoot.join(JpaTarget_.targetInfo);
|
||||
return cb.equal(targetInfoJoin.get(JpaTargetInfo_.installedDistributionSet).get(JpaDistributionSet_.id),
|
||||
distributionSetId);
|
||||
};
|
||||
return (targetRoot, query, cb) -> cb.equal(
|
||||
targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id), distributionSetId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
ALTER TABLE sp_target ADD COLUMN install_date bigint;
|
||||
ALTER TABLE sp_target ADD COLUMN address varchar(512);
|
||||
ALTER TABLE sp_target ADD COLUMN last_target_query bigint;
|
||||
ALTER TABLE sp_target ADD COLUMN request_controller_attributes bit not null;
|
||||
ALTER TABLE sp_target ADD COLUMN update_status varchar(16) not null;
|
||||
ALTER TABLE sp_target ADD COLUMN installed_distribution_set bigint;
|
||||
|
||||
UPDATE sp_target t SET install_date=(SELECT i.install_date FROM sp_target_info i WHERE t.id = i.target_id);
|
||||
UPDATE sp_target t SET address=(SELECT i.address FROM sp_target_info i WHERE t.id = i.target_id);
|
||||
UPDATE sp_target t SET last_target_query=(SELECT i.last_target_query FROM sp_target_info i WHERE t.id = i.target_id);
|
||||
UPDATE sp_target t SET request_controller_attributes=(SELECT i.request_controller_attributes FROM sp_target_info i WHERE t.id = i.target_id);
|
||||
UPDATE sp_target t SET update_status=(SELECT i.update_status FROM sp_target_info i WHERE t.id = i.target_id);
|
||||
UPDATE sp_target t SET installed_distribution_set=(SELECT i.installed_distribution_set FROM sp_target_info i WHERE t.id = i.target_id);
|
||||
|
||||
ALTER TABLE sp_target_attributes DROP CONSTRAINT fk_targ_attrib_target;
|
||||
ALTER TABLE sp_target_attributes
|
||||
ADD CONSTRAINT fk_targ_attrib_target
|
||||
FOREIGN KEY (target_id)
|
||||
REFERENCES sp_target (id)
|
||||
ON DELETE cascade;
|
||||
|
||||
ALTER TABLE sp_target_info DROP CONSTRAINT fk_target_inst_ds;
|
||||
ALTER TABLE sp_target
|
||||
ADD CONSTRAINT fk_target_inst_ds
|
||||
FOREIGN KEY (installed_distribution_set)
|
||||
REFERENCES sp_distribution_set (id);
|
||||
|
||||
ALTER TABLE sp_target_info DROP CONSTRAINT fk_targ_stat_targ;
|
||||
ALTER TABLE sp_target_info DROP INDEX sp_idx_target_info_02;
|
||||
CREATE INDEX sp_idx_target_05 ON sp_target (tenant,address);
|
||||
|
||||
DROP TABLE sp_target_info;
|
||||
@@ -0,0 +1,32 @@
|
||||
ALTER TABLE sp_target ADD COLUMN install_date bigint;
|
||||
ALTER TABLE sp_target ADD COLUMN address varchar(512);
|
||||
ALTER TABLE sp_target ADD COLUMN last_target_query bigint;
|
||||
ALTER TABLE sp_target ADD COLUMN request_controller_attributes bit not null;
|
||||
ALTER TABLE sp_target ADD COLUMN update_status varchar(16) not null;
|
||||
ALTER TABLE sp_target ADD COLUMN installed_distribution_set bigint;
|
||||
|
||||
UPDATE sp_target AS t INNER JOIN sp_target_info AS i
|
||||
ON t.id = i.target_id
|
||||
SET t.install_date = i.install_date, t.address = i.address,t.last_target_query = i.last_target_query,
|
||||
t.request_controller_attributes = i.request_controller_attributes,t.update_status = i.update_status,
|
||||
t.installed_distribution_set = i.installed_distribution_set;
|
||||
|
||||
ALTER TABLE sp_target_info DROP INDEX sp_idx_target_info_02;
|
||||
CREATE INDEX sp_idx_target_05 ON sp_target (tenant,address);
|
||||
|
||||
ALTER TABLE sp_target_attributes DROP FOREIGN KEY fk_targ_attrib_target;
|
||||
ALTER TABLE sp_target_attributes
|
||||
ADD CONSTRAINT fk_targ_attrib_target
|
||||
FOREIGN KEY (target_id)
|
||||
REFERENCES sp_target (id)
|
||||
ON DELETE cascade;
|
||||
|
||||
ALTER TABLE sp_target_info DROP FOREIGN KEY fk_target_inst_ds;
|
||||
ALTER TABLE sp_target
|
||||
ADD CONSTRAINT fk_target_inst_ds
|
||||
FOREIGN KEY (installed_distribution_set)
|
||||
REFERENCES sp_distribution_set (id);
|
||||
|
||||
ALTER TABLE sp_target_info DROP FOREIGN KEY fk_targ_stat_targ;
|
||||
|
||||
DROP TABLE sp_target_info;
|
||||
@@ -76,9 +76,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
@Autowired
|
||||
protected LocalArtifactRepository artifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
protected RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
|
||||
@@ -65,20 +65,20 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThatThrownBy(() -> artifactManagement.deleteArtifact(1234L)).isInstanceOf(EntityNotFoundException.class)
|
||||
.hasMessageContaining("1234").hasMessageContaining("Artifact");
|
||||
|
||||
assertThat(artifactManagement.findArtifact(1234L).isPresent()).isFalse();
|
||||
assertThat(artifactManagement.findArtifact(1234L)).isNotPresent();
|
||||
assertThatThrownBy(() -> artifactManagement.findArtifactBySoftwareModule(pageReq, 1234L))
|
||||
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
|
||||
.hasMessageContaining("SoftwareModule");
|
||||
assertThat(artifactManagement.findArtifactByFilename("1234").isPresent()).isFalse();
|
||||
assertThat(artifactManagement.findArtifactByFilename("1234")).isNotPresent();
|
||||
|
||||
assertThatThrownBy(() -> artifactManagement.findByFilenameAndSoftwareModule("xxx", 1234L))
|
||||
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
|
||||
.hasMessageContaining("SoftwareModule");
|
||||
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("1234", module.getId()).isPresent()).isFalse();
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("1234", module.getId())).isNotPresent();
|
||||
|
||||
assertThat(artifactManagement.findFirstArtifactBySHA1("1234").isPresent()).isFalse();
|
||||
assertThat(artifactManagement.loadArtifactBinary("1234").isPresent()).isFalse();
|
||||
assertThat(artifactManagement.findFirstArtifactBySHA1("1234")).isNotPresent();
|
||||
assertThat(artifactManagement.loadArtifactBinary("1234")).isNotPresent();
|
||||
|
||||
}
|
||||
|
||||
@@ -271,12 +271,12 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void findByFilenameAndSoftwareModule() {
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId()).isPresent()).isFalse();
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isNotPresent();
|
||||
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
|
||||
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId()).isPresent()).isTrue();
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isPresent();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -43,6 +44,7 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithSpringAuthorityRule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -83,9 +85,9 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
|
||||
.hasMessageContaining("Action");
|
||||
|
||||
assertThat(controllerManagement.findActionWithDetails(1234L).isPresent()).isFalse();
|
||||
assertThat(controllerManagement.findByControllerId("1234").isPresent()).isFalse();
|
||||
assertThat(controllerManagement.findByTargetId(1234L).isPresent()).isFalse();
|
||||
assertThat(controllerManagement.findActionWithDetails(1234L)).isNotPresent();
|
||||
assertThat(controllerManagement.findByControllerId("1234")).isNotPresent();
|
||||
assertThat(controllerManagement.findByTargetId(1234L)).isNotPresent();
|
||||
|
||||
assertThatThrownBy(() -> controllerManagement.findOldestActiveActionByTarget("1234"))
|
||||
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
|
||||
@@ -316,7 +318,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
testdataFactory.createTarget();
|
||||
assignDistributionSet(dsId, TestdataFactory.DEFAULT_CONTROLLER_ID);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
return deploymentManagement.findActiveActionsByTarget(TestdataFactory.DEFAULT_CONTROLLER_ID).get(0).getId();
|
||||
}
|
||||
@@ -371,7 +373,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final TargetUpdateStatus expectedTargetUpdateStatus, final Action.Status expectedActionActionStatus,
|
||||
final Action.Status expectedActionStatus, final boolean actionActive) {
|
||||
final TargetUpdateStatus targetStatus = targetManagement.findTargetByControllerID(controllerId).get()
|
||||
.getTargetInfo().getUpdateStatus();
|
||||
.getUpdateStatus();
|
||||
assertThat(targetStatus).isEqualTo(expectedTargetUpdateStatus);
|
||||
final Action action = deploymentManagement.findAction(actionId).get();
|
||||
assertThat(action.getStatus()).isEqualTo(expectedActionActionStatus);
|
||||
@@ -428,7 +430,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(target).as("target should not be null").isNotNull();
|
||||
|
||||
final Target sameTarget = controllerManagement.findOrRegisterTargetIfItDoesNotexist("AA", null);
|
||||
assertThat(target).as("Target should be the equals").isEqualTo(sameTarget);
|
||||
assertThat(target.getId()).as("Target should be the equals").isEqualTo(sameTarget.getId());
|
||||
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
|
||||
|
||||
// throws exception
|
||||
@@ -540,7 +542,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
assertThat(actionStatusRepository.count()).isEqualTo(3);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements())
|
||||
@@ -565,7 +567,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
|
||||
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// however, additional action status has been stored
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(4);
|
||||
@@ -577,12 +579,23 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Ensures that target attribute update is reflected by the repository.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 3) })
|
||||
public void updateTargetAttributes() {
|
||||
public void updateTargetAttributes() throws Exception {
|
||||
final String controllerId = "test123";
|
||||
testdataFactory.createTarget(controllerId);
|
||||
addAttributeAndVerify(controllerId);
|
||||
addSecondAttributeAndVerify(controllerId);
|
||||
updateAttributeAndVerify(controllerId);
|
||||
final Target target = testdataFactory.createTarget(controllerId);
|
||||
|
||||
securityRule.runAs(WithSpringAuthorityRule.withController("controller", CONTROLLER_ROLE_ANONYMOUS), () -> {
|
||||
addAttributeAndVerify(controllerId);
|
||||
addSecondAttributeAndVerify(controllerId);
|
||||
updateAttributeAndVerify(controllerId);
|
||||
return null;
|
||||
});
|
||||
|
||||
// verify that audit information has not changed
|
||||
final Target targetVerify = targetManagement.findTargetByControllerID(controllerId).get();
|
||||
assertThat(targetVerify.getCreatedBy()).isEqualTo(target.getCreatedBy());
|
||||
assertThat(targetVerify.getCreatedAt()).isEqualTo(target.getCreatedAt());
|
||||
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(target.getLastModifiedBy());
|
||||
assertThat(targetVerify.getLastModifiedAt()).isEqualTo(target.getLastModifiedAt());
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -591,8 +604,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
testData.put("test1", "testdata1");
|
||||
controllerManagement.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
}
|
||||
|
||||
@@ -602,9 +614,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
testData.put("test2", "testdata20");
|
||||
controllerManagement.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
|
||||
testData.put("test1", "testdata1");
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
}
|
||||
|
||||
@@ -615,9 +626,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
controllerManagement.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
|
||||
testData.put("test2", "testdata20");
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull();
|
||||
assertThat(action.getTarget()).as("Target in action").isNotNull();
|
||||
assertThat(action.getTarget().getAssignedDistributionSet()).as("AssignedDistributionSet of target in action")
|
||||
.isNotNull();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(action.getTarget().getControllerId()).get())
|
||||
.as("AssignedDistributionSet of target in action").isNotNull();
|
||||
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
|
||||
.as("target has update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// assign the two sets in a row
|
||||
@@ -230,10 +230,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(7);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet()).as("wrong ds")
|
||||
.isEqualTo(dsFirst);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong ds").isEqualTo(dsFirst);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel first -> back to installed
|
||||
deploymentManagement.cancelAction(firstAction.getId());
|
||||
@@ -242,10 +241,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(9);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds")
|
||||
.isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -260,8 +259,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// assign the two sets in a row
|
||||
JpaAction firstAction = assignSet(target, dsFirst);
|
||||
@@ -277,24 +276,24 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(7);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsSecond);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds")
|
||||
.isEqualTo(dsSecond);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
|
||||
.as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel second -> remain assigned until finished cancellation
|
||||
deploymentManagement.cancelAction(secondAction.getId());
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId()).get();
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(8);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsSecond);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds")
|
||||
.isEqualTo(dsSecond);
|
||||
// confirm cancellation
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
|
||||
// cancelled success -> back to dsInstalled
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong installed ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong installed ds")
|
||||
.isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -308,7 +307,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
Action assigningAction = assignSet(target, ds);
|
||||
@@ -329,9 +328,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify
|
||||
assertThat(assigningAction.getStatus()).as("wrong size of status").isEqualTo(Status.CANCELED);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds")
|
||||
.isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
|
||||
.as("wrong target update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -344,8 +343,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
final Action assigningAction = assignSet(target, ds);
|
||||
|
||||
@@ -363,11 +362,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private JpaAction assignSet(final Target target, final DistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).get().getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(ds);
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get())
|
||||
.as("wrong assigned ds").isEqualTo(ds);
|
||||
final JpaAction action = actionRepository
|
||||
.findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
|
||||
.get(0);
|
||||
@@ -425,8 +423,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Action> activeActionsByTarget = deploymentManagement
|
||||
.findActiveActionsByTarget(t.getControllerId());
|
||||
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
|
||||
assertThat(t.getTargetInfo().getUpdateStatus()).as("wrong target update status")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(t.getUpdateStatus()).as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
for (final Action ua : activeActionsByTarget) {
|
||||
assertThat(ua.getDistributionSet()).as("action has wrong ds").isEqualTo(ds);
|
||||
}
|
||||
@@ -564,37 +561,40 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verifying the correctness of the assignments
|
||||
for (final Target t : deployResWithDsA.getDeployedTargets()) {
|
||||
assertThat(t.getAssignedDistributionSet().getId()).as("assignment is not correct").isEqualTo(dsA.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get().getId())
|
||||
.as("assignment is not correct").isEqualTo(dsA.getId());
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds should be null").isNotPresent();
|
||||
}
|
||||
for (final Target t : deployResWithDsB.getDeployedTargets()) {
|
||||
assertThat(t.getAssignedDistributionSet().getId()).as("assigned ds is wrong").isEqualTo(dsB.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get().getId())
|
||||
.as("assigned ds is wrong").isEqualTo(dsB.getId());
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds should be null").isNotPresent();
|
||||
}
|
||||
for (final Target t : deployResWithDsC.getDeployedTargets()) {
|
||||
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsC.getId());
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds should not be null").isNull();
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get().getId())
|
||||
.isEqualTo(dsC.getId());
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds should not be null").isNotPresent();
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
}
|
||||
|
||||
final List<Target> updatedTsDsA = testdataFactory
|
||||
.sendUpdateActionStatusToTargets(deployResWithDsA.getDeployedTargets(), Status.FINISHED,
|
||||
Collections.singletonList("alles gut"))
|
||||
.stream().map(action -> action.getTarget()).collect(Collectors.toList());
|
||||
.stream().map(Action::getTarget).collect(Collectors.toList());
|
||||
|
||||
// verify, that dsA is deployed correctly
|
||||
assertThat(updatedTsDsA).as("ds is not deployed correctly").isEqualTo(deployResWithDsA.getDeployedTargets());
|
||||
for (final Target t_ : updatedTsDsA) {
|
||||
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get();
|
||||
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get())
|
||||
.as("assigned ds is wrong").isEqualTo(dsA);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()).get())
|
||||
.as("installed ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId()))
|
||||
.as("no actions should be active").hasSize(0);
|
||||
}
|
||||
@@ -609,18 +609,19 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// get final updated version of targets
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.findTargetByControllerID(deployResWithDsB
|
||||
.getDeployedTargets().stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
.getDeployedTargets().stream().map(Target::getControllerId).collect(Collectors.toList()));
|
||||
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsBTargets);
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets);
|
||||
|
||||
for (final Target t_ : deployed2DS) {
|
||||
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get();
|
||||
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get())
|
||||
.as("assigned ds is wrong").isEqualTo(dsA);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds should be null").isNotPresent();
|
||||
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -653,7 +654,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(dsA.getId());
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetById(dsA.getId()).isPresent()).isFalse();
|
||||
assertThat(distributionSetManagement.findDistributionSetById(dsA.getId())).isNotPresent();
|
||||
|
||||
// // verify that the ds is not physically deleted
|
||||
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
|
||||
@@ -743,9 +744,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("Active target actions are wrong").isEqualTo(1);
|
||||
assertThat(deploymentManagement.countActionsByTarget(targ.getControllerId())).as("Target actions are wrong")
|
||||
.isEqualTo(1);
|
||||
assertThat(targ.getTargetInfo().getUpdateStatus()).as("UpdateStatus of target is wrong")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targ.getAssignedDistributionSet()).as("Assigned distribution set of target is wrong").isEqualTo(dsA);
|
||||
assertThat(targ.getUpdateStatus()).as("UpdateStatus of target is wrong").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get())
|
||||
.as("Assigned distribution set of target is wrong").isEqualTo(dsA);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet())
|
||||
.as("Distribution set of actionn is wrong").isEqualTo(dsA);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet())
|
||||
@@ -762,10 +763,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertEquals("active actions are wrong", 1,
|
||||
deploymentManagement.findInActiveActionsByTarget(targ.getControllerId()).size());
|
||||
|
||||
assertEquals("tagret update status is not correct", TargetUpdateStatus.IN_SYNC,
|
||||
targ.getTargetInfo().getUpdateStatus());
|
||||
assertEquals("wrong assigned ds", dsA, targ.getAssignedDistributionSet());
|
||||
assertEquals("wrong installed ds", dsA, targ.getTargetInfo().getInstalledDistributionSet());
|
||||
assertEquals("tagret update status is not correct", TargetUpdateStatus.IN_SYNC, targ.getUpdateStatus());
|
||||
assertEquals("wrong assigned ds", dsA,
|
||||
deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get());
|
||||
assertEquals("wrong installed ds", dsA,
|
||||
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get());
|
||||
|
||||
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity();
|
||||
|
||||
@@ -773,12 +775,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertEquals("active actions are wrong", 1,
|
||||
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
|
||||
assertEquals("target status is wrong", TargetUpdateStatus.PENDING, targetManagement
|
||||
.findTargetByControllerID(targ.getControllerId()).get().getTargetInfo().getUpdateStatus());
|
||||
assertEquals("wrong assigned ds", dsB, targ.getAssignedDistributionSet());
|
||||
assertEquals("target status is wrong", TargetUpdateStatus.PENDING,
|
||||
targetManagement.findTargetByControllerID(targ.getControllerId()).get().getUpdateStatus());
|
||||
assertEquals("wrong assigned ds", dsB,
|
||||
deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get());
|
||||
assertEquals("Installed ds is wrong", dsA.getId(),
|
||||
targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()).get().getTargetInfo()
|
||||
.getInstalledDistributionSet().getId());
|
||||
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get().getId());
|
||||
assertEquals("Active ds is wrong", dsB,
|
||||
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet());
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.stream.Collectors;
|
||||
import org.eclipse.hawkbit.repository.ReportManagement;
|
||||
import org.eclipse.hawkbit.repository.ReportManagement.DateTypes;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
@@ -504,11 +503,9 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final JpaTarget createTarget = (JpaTarget) testdataFactory.createTarget(prefix + index);
|
||||
if (lastTargetQuery != null) {
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) createTarget.getTargetInfo();
|
||||
targetInfo.setNew(false);
|
||||
targetInfo
|
||||
createTarget
|
||||
.setLastTargetQuery(lastTargetQuery.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
|
||||
targetInfoRepository.save(targetInfo);
|
||||
targetRepository.save(createTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -516,10 +513,8 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
private void createTargetsWithStatus(final String prefix, final long amount, final TargetUpdateStatus status) {
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final JpaTarget target = new JpaTarget(prefix + index);
|
||||
final Target sTarget = targetRepository.save(target);
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) sTarget.getTargetInfo();
|
||||
targetInfo.setUpdateStatus(status);
|
||||
targetInfoRepository.save(targetInfo);
|
||||
target.setUpdateStatus(status);
|
||||
targetRepository.save(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -262,8 +262,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Step("Check the status of the rollout groups and the rollout")
|
||||
private void verifyRolloutAndAllGroupsAreFinished(final Rollout createdRollout) {
|
||||
rolloutManagement.handleRollouts();
|
||||
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId(
|
||||
createdRollout.getId(), new OffsetBasedPageRequest(0, 10, new Sort(Direction.ASC, "id"))).getContent();
|
||||
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement
|
||||
.findRolloutGroupsByRolloutId(createdRollout.getId(), pageReq).getContent();
|
||||
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
|
||||
@@ -568,13 +568,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// 5 targets are in the group and the DS has been assigned
|
||||
final List<RolloutGroup> rolloutGroups = createdRollout.getRolloutGroups();
|
||||
final Page<Target> targets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(),
|
||||
new OffsetBasedPageRequest(0, 20, new Sort(Direction.ASC, "id")));
|
||||
pageReq);
|
||||
final List<Target> targetList = targets.getContent();
|
||||
assertThat(targetList.size()).isEqualTo(5);
|
||||
for (final Target t : targetList) {
|
||||
final DistributionSet assignedDs = t.getAssignedDistributionSet();
|
||||
assertThat(assignedDs.getId()).isEqualTo(ds.getId());
|
||||
}
|
||||
|
||||
targets.getContent().stream().map(Target::getControllerId).map(deploymentManagement::getAssignedDistributionSet)
|
||||
.forEach(d -> assertThat(d.get().getId()).isEqualTo(ds.getId()));
|
||||
|
||||
final List<Target> targetToCancel = new ArrayList<>();
|
||||
targetToCancel.add(targetList.get(0));
|
||||
@@ -674,7 +673,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
rolloutTwo = rolloutManagement.findRolloutById(rolloutTwo.getId()).get();
|
||||
// 6 error targets are know running
|
||||
// 6 error targets are now running
|
||||
expectedTargetCountStatus = createInitStatusMap();
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 6L);
|
||||
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 9L);
|
||||
@@ -684,10 +683,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Target> targetList = targetPage.getContent();
|
||||
// 15 targets in finished/IN_SYNC status and same DS assigned
|
||||
assertThat(targetList.size()).isEqualTo(amountTargetsForRollout);
|
||||
for (final Target t : targetList) {
|
||||
final DistributionSet ds = t.getAssignedDistributionSet();
|
||||
assertThat(ds).isEqualTo(distributionSet);
|
||||
}
|
||||
targetList.stream().map(Target::getControllerId).map(deploymentManagement::getAssignedDistributionSet)
|
||||
.forEach(d -> assertThat(d.get()).isEqualTo(distributionSet));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1425,7 +1422,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = RolloutGroupUpdatedEvent.class, count = 16),
|
||||
@Expect(type = RolloutUpdatedEvent.class, count = 6),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = TargetUpdatedEvent.class, count = 4),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = TargetUpdatedEvent.class, count = 2),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2),
|
||||
@Expect(type = RolloutGroupCreatedEvent.class, count = 5),
|
||||
@Expect(type = ActionCreatedEvent.class, count = 10), @Expect(type = ActionUpdatedEvent.class, count = 2),
|
||||
@@ -1504,7 +1501,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Map<TotalTargetCountStatus.Status, Long> expectedTotalCountStates) {
|
||||
for (final Map.Entry<TotalTargetCountStatus.Status, Long> entry : expectedTotalCountStates.entrySet()) {
|
||||
final Long countReady = totalTargetCountStatus.getTotalTargetCountByStatus(entry.getKey());
|
||||
assertThat(countReady).isEqualTo(entry.getValue());
|
||||
assertThat(countReady).as("targets in status " + entry.getKey()).isEqualTo(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,11 +186,9 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).get().getAssignedDistributionSet())
|
||||
.isEqualTo(ds);
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(ds);
|
||||
final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
|
||||
assertThat(action).isNotNull();
|
||||
return action;
|
||||
@@ -289,7 +287,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: SoftwareModule is deleted
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(0);
|
||||
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId()).isPresent()).isFalse();
|
||||
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId())).isNotPresent();
|
||||
|
||||
// verify: binary data of artifact is deleted
|
||||
assertArtfiactNull(artifact1, artifact2);
|
||||
@@ -399,8 +397,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: SoftwareModuleX is deleted, and ModuelY still exists
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId()).isPresent()).isFalse();
|
||||
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId()).isPresent()).isTrue();
|
||||
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId())).isNotPresent();
|
||||
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId())).isPresent();
|
||||
|
||||
// verify: binary data of artifact is not deleted
|
||||
assertArtfiactNotNull(artifactY);
|
||||
@@ -822,7 +820,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
|
||||
.getSoftwareModule();
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist").isPresent()).isFalse();
|
||||
assertThat(softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist")).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -100,7 +100,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
for (int i = 0; i < tenants; i++) {
|
||||
final String tenantname = "tenant" + i;
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", tenantname, true, true,
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", tenantname, true, true, false,
|
||||
SpringEvalExpressions.SYSTEM_ROLE), () -> {
|
||||
systemManagement.getTenantMetadata(tenantname);
|
||||
if (artifactSize > 0) {
|
||||
|
||||
@@ -209,7 +209,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
TargetTagAssignmentResult result = toggleTagAssignment(groupA, tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetByControllerID(
|
||||
groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassigned()).isEqualTo(0);
|
||||
assertThat(result.getUnassignedEntity()).isEmpty();
|
||||
@@ -219,7 +219,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
result = toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetByControllerID(
|
||||
groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassigned()).isEqualTo(0);
|
||||
assertThat(result.getUnassignedEntity()).isEmpty();
|
||||
@@ -231,7 +231,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(result.getAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssignedEntity()).isEmpty();
|
||||
assertThat(result.getUnassigned()).isEqualTo(40);
|
||||
assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetByControllerID(
|
||||
concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
|
||||
assertThat(result.getTargetTag()).isEqualTo(tag);
|
||||
|
||||
@@ -275,7 +275,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final TargetTag toDelete = tags.iterator().next();
|
||||
|
||||
for (final Target target : targetRepository.findAll()) {
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTags())
|
||||
assertThat(tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getContent())
|
||||
.contains(toDelete);
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// check
|
||||
for (final Target target : targetRepository.findAll()) {
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTags())
|
||||
assertThat(tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getContent())
|
||||
.doesNotContain(toDelete);
|
||||
}
|
||||
assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull();
|
||||
|
||||
@@ -604,13 +604,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(result.getNumberOfElements()).isEqualTo(9);
|
||||
final List<Target> expected = new ArrayList<>();
|
||||
expected.addAll(targInstalled.stream().sorted(byId)
|
||||
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getTargetInfo().getLastTargetQuery()))
|
||||
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getLastTargetQuery()))
|
||||
.collect(Collectors.toList()));
|
||||
expected.addAll(targAssigned.stream().sorted(byId)
|
||||
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getTargetInfo().getLastTargetQuery()))
|
||||
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getLastTargetQuery()))
|
||||
.collect(Collectors.toList()));
|
||||
expected.addAll(notAssigned.stream().sorted(byId)
|
||||
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getTargetInfo().getLastTargetQuery()))
|
||||
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getLastTargetQuery()))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
assertThat(result.getContent()).containsExactly(expected.toArray(new Target[0]));
|
||||
|
||||
@@ -13,6 +13,7 @@ import static com.google.common.collect.Iterables.toArray;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -63,6 +64,40 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Stories("Target Management")
|
||||
public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Ensures that an anonymous target update is not monitored by auditing.")
|
||||
@WithUser(principal = "knownPrincipal", authorities = { SpPermission.READ_TARGET, SpPermission.UPDATE_TARGET,
|
||||
SpPermission.CREATE_TARGET }, allSpPermissions = false)
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 2) })
|
||||
public void controllerAccessDoesNotChangeAuditData() throws Exception {
|
||||
// create target first with "knownPrincipal" user and audit data
|
||||
final String knownTargetControllerId = "target1";
|
||||
final String knownCreatedBy = "knownPrincipal";
|
||||
testdataFactory.createTarget(knownTargetControllerId);
|
||||
targetManagement.updateTarget(entityFactory.target().update(knownTargetControllerId).description("updated1"));
|
||||
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId)
|
||||
.get();
|
||||
assertThat(findTargetByControllerID.getCreatedBy()).isEqualTo(knownCreatedBy);
|
||||
assertThat(findTargetByControllerID.getCreatedAt()).isNotNull();
|
||||
assertThat(findTargetByControllerID.getLastModifiedBy()).isEqualTo(knownCreatedBy);
|
||||
assertThat(findTargetByControllerID.getLastModifiedAt()).isNotNull();
|
||||
|
||||
// make an update, audit information should not be changed, run as
|
||||
// controller principal!
|
||||
securityRule.runAs(WithSpringAuthorityRule.withController("controller", CONTROLLER_ROLE_ANONYMOUS), () -> {
|
||||
targetManagement.updateTarget(entityFactory.target().update("target1").description("updated2"));
|
||||
return null;
|
||||
});
|
||||
|
||||
// verify that audit information has not changed
|
||||
final Target targetVerify = targetManagement.findTargetByControllerID(knownTargetControllerId).get();
|
||||
assertThat(targetVerify.getCreatedBy()).isEqualTo(findTargetByControllerID.getCreatedBy());
|
||||
assertThat(targetVerify.getCreatedAt()).isEqualTo(findTargetByControllerID.getCreatedAt());
|
||||
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(findTargetByControllerID.getLastModifiedBy());
|
||||
assertThat(targetVerify.getLastModifiedAt()).isEqualTo(findTargetByControllerID.getLastModifiedAt());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that retrieving the target security is only permitted with the necessary permissions.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
@@ -195,7 +230,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId());
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
|
||||
assignedTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(1));
|
||||
assignedTargets.forEach(target -> assertThat(
|
||||
tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getNumberOfElements()).isEqualTo(1));
|
||||
|
||||
TargetTag findTargetTag = tagManagement.findTargetTag("Tag1").get();
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
|
||||
@@ -206,7 +242,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId());
|
||||
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
|
||||
assertThat(unAssignTarget.getTags()).as("Tag size is wrong").isEmpty();
|
||||
assertThat(tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId())).as("Tag size is wrong")
|
||||
.isEmpty();
|
||||
findTargetTag = tagManagement.findTargetTag("Tag1").get();
|
||||
assertThat(findTargetTag.getAssignedToTargets()).as("Assigned targets are wrong").hasSize(3);
|
||||
|
||||
@@ -214,7 +251,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
findTargetTag = tagManagement.findTargetTag("Tag1").get();
|
||||
assertThat(findTargetTag.getAssignedToTargets()).as("Unassigned targets are wrong").isEmpty();
|
||||
assertThat(unAssignTargets).as("Unassigned targets are wrong").hasSize(3);
|
||||
unAssignTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(0));
|
||||
unAssignTargets.forEach(target -> assertThat(
|
||||
tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId()).getNumberOfElements())
|
||||
.isEqualTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,10 +287,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
testData.put("test1", "testdata1");
|
||||
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId));
|
||||
controllerManagement.updateControllerAttributes(controllerId, testData);
|
||||
final Target target = controllerManagement.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
return target;
|
||||
}
|
||||
@@ -287,7 +325,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(result.getActions().get(0)).status(Status.FINISHED));
|
||||
assignDistributionSet(set2.getId(), "4711");
|
||||
|
||||
target = targetManagement.findTargetByControllerIDWithDetails("4711").get();
|
||||
target = targetManagement.findTargetByControllerID("4711").get();
|
||||
// read data
|
||||
|
||||
assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong")
|
||||
@@ -298,17 +336,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isEqualTo(1);
|
||||
assertThat(targetManagement.countTargetByInstalledDistributionSet(set2.getId())).as("Target count is wrong")
|
||||
.isEqualTo(0);
|
||||
assertThat(target.getTargetInfo().getLastTargetQuery()).as("Target query is not work")
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(target.getAssignedDistributionSet()).as("Assigned ds size is wrong").isEqualTo(set2);
|
||||
assertThat(target.getTargetInfo().getInstalledDistributionSet().getId()).as("Installed ds is wrong")
|
||||
.isEqualTo(set.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that repositoy returns null if given controller ID does not exist without exception.")
|
||||
public void findTargetByControllerIDWithDetailsReturnsNullForNonexisting() {
|
||||
assertThat(targetManagement.findTargetByControllerIDWithDetails("dsfsdfsdfsd").isPresent()).isFalse();
|
||||
assertThat(target.getLastTargetQuery()).as("Target query is not work").isGreaterThanOrEqualTo(current);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4711").get()).as("Assigned ds size is wrong")
|
||||
.isEqualTo(set2);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet("4711").get()).as("Installed ds is wrong")
|
||||
.isEqualTo(set);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -356,7 +388,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
_target: for (final Target tl : targets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tt : t.getTags()) {
|
||||
for (final Tag tt : tagManagement.findAllTargetTags(pageReq, tl.getControllerId())) {
|
||||
for (final Tag tag : tags) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
continue _target;
|
||||
@@ -375,7 +407,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : t.getTags()) {
|
||||
for (final Tag tt : tagManagement.findAllTargetTags(pageReq, tl.getControllerId())) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
fail("Target should have no tags");
|
||||
}
|
||||
@@ -507,14 +539,16 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag.getId()));
|
||||
|
||||
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId()).get();
|
||||
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags).containsAll(t1Tags);
|
||||
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags)
|
||||
.doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
|
||||
assertThat(tagManagement.findAllTargetTags(pageReq, t11.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).containsAll(t1Tags);
|
||||
assertThat(tagManagement.findAllTargetTags(pageReq, t11.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
|
||||
|
||||
final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId()).get();
|
||||
assertThat(t21.getTags()).as("Tag size is wrong").hasSize(noT2Tags).containsAll(t2Tags);
|
||||
assertThat(t21.getTags()).as("Tag size is wrong").hasSize(noT2Tags)
|
||||
.doesNotContain(Iterables.toArray(t1Tags, TargetTag.class));
|
||||
assertThat(tagManagement.findAllTargetTags(pageReq, t21.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).containsAll(t2Tags);
|
||||
assertThat(tagManagement.findAllTargetTags(pageReq, t21.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).doesNotContain(Iterables.toArray(t1Tags, TargetTag.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -644,29 +678,6 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
checkTargetHasNotTags(targABCs, targTagC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Retrieves targets by ID with lazy loading of the tags. Checks the successfull load.")
|
||||
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 25),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 25) })
|
||||
public void findTargetsByControllerIDsWithTags() {
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag"));
|
||||
|
||||
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
|
||||
|
||||
toggleTagAssignment(targAs, targTagA);
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetsByControllerIDsWithTags(targAs.stream().map(Target::getControllerId).collect(toList())))
|
||||
.as("Target count is wrong").hasSize(25);
|
||||
|
||||
// no lazy loading exception and tag correctly assigned
|
||||
assertThat(targetManagement
|
||||
.findTargetsByControllerIDsWithTags(targAs.stream().map(Target::getControllerId).collect(toList()))
|
||||
.stream().map(target -> target.getTags().contains(targTagA)).collect(toList()))
|
||||
.as("Tags not correctly assigned").containsOnly(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test that NO TAG functionality which gives all targets with no tag assigned.")
|
||||
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1),
|
||||
@@ -700,8 +711,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId)
|
||||
.get();
|
||||
assertThat(findTargetByControllerID).isNotNull();
|
||||
assertThat(findTargetByControllerID.getTargetInfo()).isNotNull();
|
||||
assertThat(findTargetByControllerID.getTargetInfo().getPollStatus()).isNotNull();
|
||||
assertThat(findTargetByControllerID.getPollStatus()).isNotNull();
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
@@ -146,12 +145,13 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
final int count) {
|
||||
final List<Long> targetIds = targets.stream().map(Target::getId).collect(Collectors.toList());
|
||||
|
||||
final Slice<Target> targetsAll = targetManagement.findTargetsAll(new PageRequest(0, 1000));
|
||||
final Slice<Target> targetsAll = targetManagement.findTargetsAll(pageReq);
|
||||
assertThat(targetsAll).as("Count of targets").hasSize(count);
|
||||
|
||||
for (final Target target : targetsAll) {
|
||||
if (targetIds.contains(target.getId())) {
|
||||
assertThat(target.getAssignedDistributionSet()).as("assigned DS").isEqualTo(set);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get())
|
||||
.as("assigned DS").isEqualTo(set);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,18 +170,12 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Test filter target by lastTargetQuery")
|
||||
public void testFilterByLastTargetQuery() throws InterruptedException {
|
||||
assertRSQLQuery(
|
||||
TargetFields.LASTCONTROLLERREQUESTAT.name() + "==" + target.getTargetInfo().getLastTargetQuery(), 1);
|
||||
assertRSQLQuery(
|
||||
TargetFields.LASTCONTROLLERREQUESTAT.name() + "!=" + target.getTargetInfo().getLastTargetQuery(), 1);
|
||||
assertRSQLQuery(
|
||||
TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + target.getTargetInfo().getLastTargetQuery(), 0);
|
||||
assertRSQLQuery(
|
||||
TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + target2.getTargetInfo().getLastTargetQuery(), 1);
|
||||
assertRSQLQuery(
|
||||
TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + target.getTargetInfo().getLastTargetQuery(), 1);
|
||||
assertRSQLQuery(
|
||||
TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + target2.getTargetInfo().getLastTargetQuery(), 0);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "==" + target.getLastTargetQuery(), 1);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "!=" + target.getLastTargetQuery(), 1);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + target.getLastTargetQuery(), 0);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + target2.getLastTargetQuery(), 1);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + target.getLastTargetQuery(), 1);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + target2.getLastTargetQuery(), 0);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) {
|
||||
|
||||
@@ -502,7 +502,12 @@ public class TestdataFactory {
|
||||
*/
|
||||
public Target createTarget(final String controllerId) {
|
||||
final Target target = targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId));
|
||||
assertThat(target.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
assertThat(target.getCreatedBy()).isNotNull();
|
||||
assertThat(target.getCreatedAt()).isNotNull();
|
||||
assertThat(target.getLastModifiedBy()).isNotNull();
|
||||
assertThat(target.getLastModifiedAt()).isNotNull();
|
||||
|
||||
assertThat(target.getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
new UserPrincipal(annotation.principal(), annotation.principal(), annotation.principal(),
|
||||
annotation.principal(), null, annotation.tenantId()),
|
||||
annotation.credentials(), authorities);
|
||||
testingAuthenticationToken
|
||||
.setDetails(new TenantAwareAuthenticationDetails(annotation.tenantId(), false));
|
||||
testingAuthenticationToken.setDetails(
|
||||
new TenantAwareAuthenticationDetails(annotation.tenantId(), annotation.controller()));
|
||||
return testingAuthenticationToken;
|
||||
}
|
||||
|
||||
@@ -171,33 +171,39 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
}
|
||||
}
|
||||
|
||||
public static WithUser withController(final String principal, final String... authorities) {
|
||||
return withUserAndTenant(principal, "default", true, true, true, authorities);
|
||||
}
|
||||
|
||||
public static WithUser withUser(final String principal, final String... authorities) {
|
||||
return withUserAndTenant(principal, "default", true, true, authorities);
|
||||
return withUserAndTenant(principal, "default", true, true, false, authorities);
|
||||
}
|
||||
|
||||
public static WithUser withUser(final String principal, final boolean allSpPermision, final String... authorities) {
|
||||
return withUserAndTenant(principal, "default", true, allSpPermision, authorities);
|
||||
return withUserAndTenant(principal, "default", true, allSpPermision, false, authorities);
|
||||
}
|
||||
|
||||
public static WithUser withUser(final boolean autoCreateTenant) {
|
||||
return withUserAndTenant("bumlux", "default", autoCreateTenant, true, new String[] {});
|
||||
return withUserAndTenant("bumlux", "default", autoCreateTenant, true, false, new String[] {});
|
||||
}
|
||||
|
||||
public static WithUser withUserAndTenant(final String principal, final String tenant, final String... authorities) {
|
||||
return withUserAndTenant(principal, tenant, true, true, new String[] {});
|
||||
return withUserAndTenant(principal, tenant, true, true, false, new String[] {});
|
||||
}
|
||||
|
||||
public static WithUser withUserAndTenant(final String principal, final String tenant,
|
||||
final boolean autoCreateTenant, final boolean allSpPermission, final String... authorities) {
|
||||
return createWithUser(principal, tenant, autoCreateTenant, allSpPermission, authorities);
|
||||
final boolean autoCreateTenant, final boolean allSpPermission, final boolean controller,
|
||||
final String... authorities) {
|
||||
return createWithUser(principal, tenant, autoCreateTenant, allSpPermission, controller, authorities);
|
||||
}
|
||||
|
||||
private static WithUser privilegedUser() {
|
||||
return createWithUser("bumlux", "default", true, true, new String[] { "ROLE_CONTROLLER", "ROLE_SYSTEM_CODE" });
|
||||
return createWithUser("bumlux", "default", true, true, false,
|
||||
new String[] { "ROLE_CONTROLLER", "ROLE_SYSTEM_CODE" });
|
||||
}
|
||||
|
||||
private static WithUser createWithUser(final String principal, final String tenant, final boolean autoCreateTenant,
|
||||
final boolean allSpPermission, final String... authorities) {
|
||||
final boolean allSpPermission, final boolean controller, final String... authorities) {
|
||||
return new WithUser() {
|
||||
|
||||
@Override
|
||||
@@ -239,6 +245,11 @@ public class WithSpringAuthorityRule implements TestRule {
|
||||
public boolean autoCreateTenant() {
|
||||
return autoCreateTenant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean controller() {
|
||||
return controller;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,4 +74,6 @@ public @interface WithUser {
|
||||
* @return removeFromAllPermission
|
||||
*/
|
||||
String[] removeFromAllPermission() default {};
|
||||
|
||||
boolean controller() default false;
|
||||
}
|
||||
|
||||
@@ -417,8 +417,7 @@ public abstract class JsonBuilder {
|
||||
int i = 0;
|
||||
for (final Target target : targets) {
|
||||
try {
|
||||
final String address = target.getTargetInfo().getAddress() != null
|
||||
? target.getTargetInfo().getAddress().toString() : null;
|
||||
final String address = target.getAddress() != null ? target.getAddress().toString() : null;
|
||||
|
||||
final String token = withToken ? target.getSecurityToken() : null;
|
||||
|
||||
|
||||
@@ -17,16 +17,8 @@ import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||
* {@link AbstractAuthenticationToken#getDetails()} which is stored in the
|
||||
* spring security authentication token details to transport the principal and
|
||||
* tenant in the security context session.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TenantAwareAuthenticationDetails implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String tenant;
|
||||
@@ -58,4 +50,10 @@ public class TenantAwareAuthenticationDetails implements Serializable {
|
||||
public boolean isController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TenantAwareAuthenticationDetails [tenant=" + tenant + ", controller=" + controller + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.ui.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
@@ -245,12 +244,10 @@ public abstract class AbstractTableDetailsLayout<T extends NamedEntity> extends
|
||||
/*
|
||||
* display Attributes details in Target details.
|
||||
*/
|
||||
|
||||
protected void updateAttributesLayout(final Target target) {
|
||||
if (null != target && null != target.getTargetInfo()
|
||||
&& null != target.getTargetInfo().getControllerAttributes()) {
|
||||
protected void updateAttributesLayout(final Map<String, String> attributes) {
|
||||
if (null != attributes) {
|
||||
attributesLayout.removeAllComponents();
|
||||
for (final Map.Entry<String, String> entry : target.getTargetInfo().getControllerAttributes().entrySet()) {
|
||||
for (final Map.Entry<String, String> entry : attributes.entrySet()) {
|
||||
final Label conAttributeLabel = SPUIComponentProvider.createNameValueLabel(
|
||||
entry.getKey().concat(" : "),
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(entry.getValue()) == null ? "" : entry.getValue());
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.common.tagdetails;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -28,6 +25,8 @@ import org.vaadin.spring.events.EventBus.UIEventBus;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* Implementation of Target tag token.
|
||||
*
|
||||
@@ -74,9 +73,8 @@ public class TargetTagToken extends AbstractTargetTagToken<Target> {
|
||||
}
|
||||
|
||||
private TargetTagAssignmentResult toggleAssignment(final String tagNameSelected) {
|
||||
final Set<String> targetList = new HashSet<>();
|
||||
targetList.add(selectedEntity.getControllerId());
|
||||
final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected);
|
||||
final TargetTagAssignmentResult result = targetManagement
|
||||
.toggleTagAssignment(Lists.newArrayList(selectedEntity.getControllerId()), tagNameSelected);
|
||||
processTargetTagAssigmentResult(result);
|
||||
uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n));
|
||||
return result;
|
||||
@@ -99,7 +97,8 @@ public class TargetTagToken extends AbstractTargetTagToken<Target> {
|
||||
protected void displayAlreadyAssignedTags() {
|
||||
removePreviouslyAddedTokens();
|
||||
if (selectedEntity != null) {
|
||||
for (final TargetTag tag : selectedEntity.getTags()) {
|
||||
for (final TargetTag tag : tagManagement.findAllTargetTags(new PageRequest(0, MAX_TAGS),
|
||||
selectedEntity.getControllerId())) {
|
||||
addNewToken(tag.getId());
|
||||
}
|
||||
}
|
||||
@@ -114,10 +113,6 @@ public class TargetTagToken extends AbstractTargetTagToken<Target> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param assignmentResult
|
||||
*/
|
||||
public void processTargetTagAssigmentResult(final TargetTagAssignmentResult assignmentResult) {
|
||||
final TargetTag targetTag = assignmentResult.getTargetTag();
|
||||
if (isAssign(assignmentResult)) {
|
||||
@@ -129,7 +124,7 @@ public class TargetTagToken extends AbstractTargetTagToken<Target> {
|
||||
|
||||
protected boolean isAssign(final TargetTagAssignmentResult assignmentResult) {
|
||||
if (assignmentResult.getAssigned() > 0 && managementUIState.getLastSelectedTargetId() != null) {
|
||||
return assignmentResult.getAssignedEntity().stream().map(t -> t.getId())
|
||||
return assignmentResult.getAssignedEntity().stream().map(Target::getId)
|
||||
.anyMatch(controllerId -> controllerId.equals(managementUIState.getLastSelectedTargetId()));
|
||||
}
|
||||
return false;
|
||||
@@ -137,7 +132,7 @@ public class TargetTagToken extends AbstractTargetTagToken<Target> {
|
||||
|
||||
protected boolean isUnassign(final TargetTagAssignmentResult assignmentResult) {
|
||||
if (assignmentResult.getUnassigned() > 0 && managementUIState.getLastSelectedTargetId() != null) {
|
||||
return assignmentResult.getUnassignedEntity().stream().map(t -> t.getId())
|
||||
return assignmentResult.getUnassignedEntity().stream().map(Target::getId)
|
||||
.anyMatch(controllerId -> controllerId.equals(managementUIState.getLastSelectedTargetId()));
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -70,15 +70,15 @@ public abstract class AbstractNotificationView extends VerticalLayout implements
|
||||
return;
|
||||
}
|
||||
|
||||
eventContainer.getEvents().stream().filter(event -> !anyEventMatch(event)).forEach(event -> {
|
||||
eventContainer.getEvents().stream().filter(this::noEventMatch).forEach(event -> {
|
||||
notificationUnreadButton.incrementUnreadNotification(this, eventContainer);
|
||||
viewUnreadNotifcations.incrementAndGet();
|
||||
});
|
||||
getDashboardMenuItem().setNotificationUnreadValue(viewUnreadNotifcations);
|
||||
}
|
||||
|
||||
private boolean anyEventMatch(final TenantAwareEvent tenantAwareEvent) {
|
||||
return skipUiEventsCache.asMap().keySet().stream()
|
||||
private boolean noEventMatch(final TenantAwareEvent tenantAwareEvent) {
|
||||
return !skipUiEventsCache.asMap().keySet().stream()
|
||||
.anyMatch(uiEvent -> uiEvent.matchRemoteEvent(tenantAwareEvent));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ import java.net.URI;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.PollStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
/**
|
||||
@@ -58,8 +58,6 @@ public class ProxyTarget implements Serializable {
|
||||
|
||||
private Long createdAt;
|
||||
|
||||
private TargetInfo targetInfo;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -92,14 +90,6 @@ public class ProxyTarget implements Serializable {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public TargetInfo getTargetInfo() {
|
||||
return targetInfo;
|
||||
}
|
||||
|
||||
public void setTargetInfo(final TargetInfo targetInfo) {
|
||||
this.targetInfo = targetInfo;
|
||||
}
|
||||
|
||||
public String getCreatedByUser() {
|
||||
return createdByUser;
|
||||
}
|
||||
|
||||
@@ -104,21 +104,19 @@ public class CustomTargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
|
||||
prxyTarget.setName(targ.getName());
|
||||
prxyTarget.setDescription(targ.getDescription());
|
||||
prxyTarget.setControllerId(targ.getControllerId());
|
||||
prxyTarget.setInstallationDate(targ.getTargetInfo().getInstallationDate());
|
||||
prxyTarget.setAddress(targ.getTargetInfo().getAddress());
|
||||
prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery());
|
||||
prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus());
|
||||
prxyTarget.setInstallationDate(targ.getInstallationDate());
|
||||
prxyTarget.setAddress(targ.getAddress());
|
||||
prxyTarget.setLastTargetQuery(targ.getLastTargetQuery());
|
||||
prxyTarget.setUpdateStatus(targ.getUpdateStatus());
|
||||
prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt()));
|
||||
prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt()));
|
||||
prxyTarget.setCreatedAt(targ.getCreatedAt());
|
||||
prxyTarget.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(targ));
|
||||
prxyTarget.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(targ));
|
||||
|
||||
prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus());
|
||||
prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery());
|
||||
prxyTarget.setTargetInfo(targ.getTargetInfo());
|
||||
prxyTarget.setPollStatusToolTip(
|
||||
HawkbitCommonUtil.getPollStatusToolTip(prxyTarget.getTargetInfo().getPollStatus(), getI18N()));
|
||||
prxyTarget.setUpdateStatus(targ.getUpdateStatus());
|
||||
prxyTarget.setLastTargetQuery(targ.getLastTargetQuery());
|
||||
prxyTarget.setPollStatusToolTip(HawkbitCommonUtil.getPollStatusToolTip(targ.getPollStatus(), getI18N()));
|
||||
proxyTargetBeans.add(prxyTarget);
|
||||
}
|
||||
return proxyTargetBeans;
|
||||
|
||||
@@ -141,7 +141,7 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW
|
||||
managementViewClientCriterion);
|
||||
this.distributionTableLayoutNew = new DistributionTableLayout(i18n, eventBus, permChecker, managementUIState,
|
||||
distributionSetManagement, managementViewClientCriterion, entityFactory, uiNotification, tagManagement,
|
||||
systemManagement, targetManagement);
|
||||
systemManagement, targetManagement, deploymentManagement);
|
||||
this.deleteAndActionsLayout = new DeleteActionsLayout(i18n, permChecker, eventBus, uiNotification,
|
||||
tagManagement, managementViewClientCriterion, managementUIState, targetManagement, targetTable,
|
||||
deploymentManagement, distributionSetManagement);
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent;
|
||||
@@ -79,9 +80,10 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
private final SpPermissionChecker permissionChecker;
|
||||
private final ManagementUIState managementUIState;
|
||||
private final ManagementViewClientCriterion managementViewClientCriterion;
|
||||
private final transient TargetManagement targetService;
|
||||
private final transient TargetManagement targetManagement;
|
||||
private final DsMetadataPopupLayout dsMetadataPopupLayout;
|
||||
private final transient DistributionSetManagement distributionSetManagement;
|
||||
private final transient DeploymentManagement deploymentManagement;
|
||||
|
||||
private final String notAllowedMsg;
|
||||
private boolean isDistPinned;
|
||||
@@ -89,16 +91,18 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
|
||||
DistributionTable(final UIEventBus eventBus, final VaadinMessageSource i18n, final SpPermissionChecker permissionChecker,
|
||||
final UINotification notification, final ManagementUIState managementUIState,
|
||||
final ManagementViewClientCriterion managementViewClientCriterion, final TargetManagement targetService,
|
||||
final ManagementViewClientCriterion managementViewClientCriterion, final TargetManagement targetManagement,
|
||||
final DsMetadataPopupLayout dsMetadataPopupLayout,
|
||||
final DistributionSetManagement distributionSetManagement) {
|
||||
final DistributionSetManagement distributionSetManagement,
|
||||
final DeploymentManagement deploymentManagement) {
|
||||
super(eventBus, i18n, notification);
|
||||
this.permissionChecker = permissionChecker;
|
||||
this.managementUIState = managementUIState;
|
||||
this.managementViewClientCriterion = managementViewClientCriterion;
|
||||
this.targetService = targetService;
|
||||
this.targetManagement = targetManagement;
|
||||
this.dsMetadataPopupLayout = dsMetadataPopupLayout;
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
notAllowedMsg = i18n.getMessage("message.action.not.allowed");
|
||||
|
||||
addNewContainerDS();
|
||||
@@ -391,7 +395,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
event.getTransferable().getSourceComponent().getId(), SPUIDefinitions.TARGET_TAG_ID_PREFIXS);
|
||||
// get all the targets assigned to the tag
|
||||
// assign dist to those targets
|
||||
final List<Target> assignedTargets = targetService.findTargetsByTag(targetTagName);
|
||||
final List<Target> assignedTargets = targetManagement.findTargetsByTag(targetTagName);
|
||||
if (!assignedTargets.isEmpty()) {
|
||||
assignTargetToDs(getItem(distItemId), assignedTargets);
|
||||
} else {
|
||||
@@ -407,7 +411,7 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
final AbstractSelectTargetDetails dropData = (AbstractSelectTargetDetails) event.getTargetDetails();
|
||||
|
||||
final Object distItemId = dropData.getItemIdOver();
|
||||
assignTargetToDs(getItem(distItemId), targetService.findTargetAllById(targetIdSet));
|
||||
assignTargetToDs(getItem(distItemId), targetManagement.findTargetAllById(targetIdSet));
|
||||
|
||||
}
|
||||
|
||||
@@ -522,22 +526,15 @@ public class DistributionTable extends AbstractNamedVersionTable<DistributionSet
|
||||
private void styleDistributionTableOnPinning() {
|
||||
|
||||
managementUIState.getDistributionTableFilters().getPinnedTarget().map(TargetIdName::getControllerId)
|
||||
.map(targetService::findTargetByControllerIDWithDetails)
|
||||
.ifPresent(pinnedTarget -> pinnedTarget.ifPresent(target -> {
|
||||
.ifPresent(controllerId -> {
|
||||
|
||||
final Long installedDistId = deploymentManagement.getAssignedDistributionSet(controllerId)
|
||||
.map(DistributionSet::getId).orElse(null);
|
||||
final Long assignedDistId = deploymentManagement.getAssignedDistributionSet(controllerId)
|
||||
.map(DistributionSet::getId).orElse(null);
|
||||
|
||||
final DistributionSet assignedDistribution = target.getAssignedDistributionSet();
|
||||
final DistributionSet installedDistribution = target.getTargetInfo().getInstalledDistributionSet();
|
||||
Long installedDistId = null;
|
||||
Long assignedDistId = null;
|
||||
if (null != installedDistribution) {
|
||||
installedDistId = installedDistribution.getId();
|
||||
}
|
||||
if (null != assignedDistribution) {
|
||||
assignedDistId = assignedDistribution.getId();
|
||||
}
|
||||
styleDistributionSetTable(installedDistId, assignedDistId);
|
||||
}));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private static String getPinnedDistributionStyle(final Long installedDistItemIds,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.management.dstable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
@@ -34,7 +35,8 @@ public class DistributionTableLayout extends AbstractTableLayout<DistributionTab
|
||||
final DistributionSetManagement distributionSetManagement,
|
||||
final ManagementViewClientCriterion managementViewClientCriterion, final EntityFactory entityFactory,
|
||||
final UINotification notification, final TagManagement tagManagement,
|
||||
final SystemManagement systemManagement, final TargetManagement targetService) {
|
||||
final SystemManagement systemManagement, final TargetManagement targetManagement,
|
||||
final DeploymentManagement deploymentManagement) {
|
||||
|
||||
final DistributionAddUpdateWindowLayout distributionAddUpdateWindowLayout = new DistributionAddUpdateWindowLayout(
|
||||
i18n, notification, eventBus, distributionSetManagement, systemManagement, entityFactory, null);
|
||||
@@ -43,8 +45,8 @@ public class DistributionTableLayout extends AbstractTableLayout<DistributionTab
|
||||
distributionSetManagement, entityFactory, permissionChecker);
|
||||
|
||||
final DistributionTable distributionTable = new DistributionTable(eventBus, i18n, permissionChecker,
|
||||
notification, managementUIState, managementViewClientCriterion, targetService, dsMetadataPopupLayout,
|
||||
distributionSetManagement);
|
||||
notification, managementUIState, managementViewClientCriterion, targetManagement, dsMetadataPopupLayout,
|
||||
distributionSetManagement, deploymentManagement);
|
||||
|
||||
super.init(new DistributionTableHeader(i18n, permissionChecker, eventBus, managementUIState), distributionTable,
|
||||
new DistributionDetails(i18n, eventBus, permissionChecker, managementUIState, distributionSetManagement,
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
@@ -23,10 +24,10 @@ import org.eclipse.hawkbit.ui.common.UserDetailsFormatter;
|
||||
import org.eclipse.hawkbit.ui.components.ProxyTarget;
|
||||
import org.eclipse.hawkbit.ui.management.state.ManagementUIState;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -53,6 +54,7 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
|
||||
private String searchText;
|
||||
private Boolean noTagClicked;
|
||||
private transient TargetManagement targetManagement;
|
||||
private transient DeploymentManagement deploymentManagement;
|
||||
private transient VaadinMessageSource i18N;
|
||||
private Long pinnedDistId;
|
||||
private Long targetFilterQueryId;
|
||||
@@ -129,10 +131,10 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
|
||||
prxyTarget.setName(targ.getName());
|
||||
prxyTarget.setDescription(targ.getDescription());
|
||||
prxyTarget.setControllerId(targ.getControllerId());
|
||||
prxyTarget.setInstallationDate(targ.getTargetInfo().getInstallationDate());
|
||||
prxyTarget.setAddress(targ.getTargetInfo().getAddress());
|
||||
prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery());
|
||||
prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus());
|
||||
prxyTarget.setInstallationDate(targ.getInstallationDate());
|
||||
prxyTarget.setAddress(targ.getAddress());
|
||||
prxyTarget.setLastTargetQuery(targ.getLastTargetQuery());
|
||||
prxyTarget.setUpdateStatus(targ.getUpdateStatus());
|
||||
prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt()));
|
||||
prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt()));
|
||||
prxyTarget.setCreatedAt(targ.getCreatedAt());
|
||||
@@ -143,17 +145,15 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
|
||||
prxyTarget.setInstalledDistributionSet(null);
|
||||
prxyTarget.setAssignedDistributionSet(null);
|
||||
} else {
|
||||
getTargetManagement().findTargetByControllerIDWithDetails(targ.getControllerId()).ifPresent(target -> {
|
||||
prxyTarget.setInstalledDistributionSet(target.getTargetInfo().getInstalledDistributionSet());
|
||||
prxyTarget.setAssignedDistributionSet(target.getAssignedDistributionSet());
|
||||
});
|
||||
getDeploymentManagement().getAssignedDistributionSet(targ.getControllerId())
|
||||
.ifPresent(prxyTarget::setAssignedDistributionSet);
|
||||
getDeploymentManagement().getInstalledDistributionSet(targ.getControllerId())
|
||||
.ifPresent(prxyTarget::setInstalledDistributionSet);
|
||||
}
|
||||
|
||||
prxyTarget.setUpdateStatus(targ.getTargetInfo().getUpdateStatus());
|
||||
prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery());
|
||||
prxyTarget.setTargetInfo(targ.getTargetInfo());
|
||||
prxyTarget.setPollStatusToolTip(
|
||||
HawkbitCommonUtil.getPollStatusToolTip(prxyTarget.getTargetInfo().getPollStatus(), getI18N()));
|
||||
prxyTarget.setUpdateStatus(targ.getUpdateStatus());
|
||||
prxyTarget.setLastTargetQuery(targ.getLastTargetQuery());
|
||||
prxyTarget.setPollStatusToolTip(HawkbitCommonUtil.getPollStatusToolTip(targ.getPollStatus(), getI18N()));
|
||||
proxyTargetBeans.add(prxyTarget);
|
||||
}
|
||||
return proxyTargetBeans;
|
||||
@@ -214,6 +214,13 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
|
||||
return targetManagement;
|
||||
}
|
||||
|
||||
private DeploymentManagement getDeploymentManagement() {
|
||||
if (deploymentManagement == null) {
|
||||
deploymentManagement = SpringContextHelper.getBean(DeploymentManagement.class);
|
||||
}
|
||||
return deploymentManagement;
|
||||
}
|
||||
|
||||
private ManagementUIState getManagementUIState() {
|
||||
if (managementUIState == null) {
|
||||
managementUIState = SpringContextHelper.getBean(ManagementUIState.class);
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.targettable;
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
@@ -56,18 +57,24 @@ public class TargetDetails extends AbstractTableDetailsLayout<Target> {
|
||||
|
||||
private final TargetAddUpdateWindowLayout targetAddUpdateWindowLayout;
|
||||
|
||||
private final transient TargetManagement targetManagement;
|
||||
|
||||
private final transient DeploymentManagement deploymentManagement;
|
||||
|
||||
private VerticalLayout assignedDistLayout;
|
||||
private VerticalLayout installedDistLayout;
|
||||
|
||||
TargetDetails(final VaadinMessageSource i18n, final UIEventBus eventBus, final SpPermissionChecker permissionChecker,
|
||||
final ManagementUIState managementUIState, final UINotification uiNotification,
|
||||
final TagManagement tagManagement, final TargetManagement targetManagement,
|
||||
final EntityFactory entityFactory) {
|
||||
final DeploymentManagement deploymentManagement, final EntityFactory entityFactory) {
|
||||
super(i18n, eventBus, permissionChecker, managementUIState);
|
||||
this.targetTagToken = new TargetTagToken(permissionChecker, i18n, uiNotification, eventBus, managementUIState,
|
||||
tagManagement, targetManagement);
|
||||
targetAddUpdateWindowLayout = new TargetAddUpdateWindowLayout(i18n, targetManagement, eventBus, uiNotification,
|
||||
entityFactory);
|
||||
this.targetManagement = targetManagement;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
addTabs(detailsTab);
|
||||
restoreState();
|
||||
}
|
||||
@@ -141,18 +148,22 @@ public class TargetDetails extends AbstractTableDetailsLayout<Target> {
|
||||
@Override
|
||||
protected void populateDetailsWidget() {
|
||||
if (getSelectedBaseEntity() != null) {
|
||||
updateDetailsLayout(getSelectedBaseEntity().getControllerId(),
|
||||
getSelectedBaseEntity().getTargetInfo().getAddress(), getSelectedBaseEntity().getSecurityToken(),
|
||||
SPDateTimeUtil.getFormattedDate(getSelectedBaseEntity().getTargetInfo().getLastTargetQuery()));
|
||||
populateDistributionDtls(installedDistLayout,
|
||||
getSelectedBaseEntity().getTargetInfo().getInstalledDistributionSet());
|
||||
populateDistributionDtls(assignedDistLayout, getSelectedBaseEntity().getAssignedDistributionSet());
|
||||
updateAttributesLayout(targetManagement.getControllerAttributes(getSelectedBaseEntity().getControllerId()));
|
||||
|
||||
updateDetailsLayout(getSelectedBaseEntity().getControllerId(), getSelectedBaseEntity().getAddress(),
|
||||
getSelectedBaseEntity().getSecurityToken(),
|
||||
SPDateTimeUtil.getFormattedDate(getSelectedBaseEntity().getLastTargetQuery()));
|
||||
|
||||
populateDistributionDtls(installedDistLayout, deploymentManagement
|
||||
.getAssignedDistributionSet(getSelectedBaseEntity().getControllerId()).orElse(null));
|
||||
populateDistributionDtls(assignedDistLayout, deploymentManagement
|
||||
.getInstalledDistributionSet(getSelectedBaseEntity().getControllerId()).orElse(null));
|
||||
} else {
|
||||
updateDetailsLayout(null, null, null, null);
|
||||
populateDistributionDtls(installedDistLayout, null);
|
||||
populateDistributionDtls(assignedDistLayout, null);
|
||||
}
|
||||
updateAttributesLayout(getSelectedBaseEntity());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.RemoteEntityEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
@@ -145,9 +144,9 @@ public class TargetTable extends AbstractTable<Target, Long> {
|
||||
if (isFilterEnabled()) {
|
||||
refreshTargets();
|
||||
} else {
|
||||
eventContainer.getEvents().stream().filter(event -> visibleItemIds.contains(event.getEntityId())).filter(
|
||||
event -> !Objects.isNull(event.getEntity()) && !Objects.isNull(event.getEntity().getTargetInfo()))
|
||||
.forEach(event -> updateVisibleItemOnEvent(event.getEntity().getTargetInfo()));
|
||||
eventContainer.getEvents().stream().filter(event -> visibleItemIds.contains(event.getEntityId()))
|
||||
.filter(event -> !Objects.isNull(event.getEntity()))
|
||||
.forEach(event -> updateVisibleItemOnEvent(event.getEntity()));
|
||||
}
|
||||
publishTargetSelectedEntityForRefresh(eventContainer.getEvents().stream());
|
||||
}
|
||||
@@ -668,15 +667,13 @@ public class TargetTable extends AbstractTable<Target, Long> {
|
||||
* registered for the target update status. That listener will
|
||||
* update the new status icon showing for this target in the table.
|
||||
*/
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS)
|
||||
.setValue(updatedTarget.getTargetInfo().getUpdateStatus());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).setValue(updatedTarget.getUpdateStatus());
|
||||
/*
|
||||
* Update the last query which will trigger the value change lister
|
||||
* registered for the target last query column. That listener will
|
||||
* update the latest query date for this target in the tooltip.
|
||||
*/
|
||||
item.getItemProperty(SPUILabelDefinitions.LAST_QUERY_DATE)
|
||||
.setValue(updatedTarget.getTargetInfo().getLastTargetQuery());
|
||||
item.getItemProperty(SPUILabelDefinitions.LAST_QUERY_DATE).setValue(updatedTarget.getLastTargetQuery());
|
||||
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY)
|
||||
.setValue(UserDetailsFormatter.loadAndFormatLastModifiedBy(updatedTarget));
|
||||
@@ -784,17 +781,16 @@ public class TargetTable extends AbstractTable<Target, Long> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void updateVisibleItemOnEvent(final TargetInfo targetInfo) {
|
||||
final Target target = targetInfo.getTarget();
|
||||
private void updateVisibleItemOnEvent(final Target target) {
|
||||
final Long targetId = target.getId();
|
||||
|
||||
final LazyQueryContainer targetContainer = (LazyQueryContainer) getContainerDataSource();
|
||||
final Item item = targetContainer.getItem(targetId);
|
||||
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).setValue(targetInfo.getUpdateStatus());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_TARGET_STATUS).setValue(target.getUpdateStatus());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_NAME).setValue(target.getName());
|
||||
item.getItemProperty(SPUILabelDefinitions.VAR_POLL_STATUS_TOOL_TIP)
|
||||
.setValue(HawkbitCommonUtil.getPollStatusToolTip(targetInfo.getPollStatus(), i18n));
|
||||
.setValue(HawkbitCommonUtil.getPollStatusToolTip(target.getPollStatus(), i18n));
|
||||
}
|
||||
|
||||
private boolean isLastSelectedTarget(final Long targetId) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class TargetTableLayout extends AbstractTableLayout<TargetTable> {
|
||||
final Executor uiExecutor) {
|
||||
this.eventBus = eventBus;
|
||||
this.targetDetails = new TargetDetails(i18n, eventbus, permissionChecker, managementUIState, uinotification,
|
||||
tagManagement, targetManagement, entityFactory);
|
||||
tagManagement, targetManagement, deploymentManagement, entityFactory);
|
||||
this.targetTableHeader = new TargetTableHeader(i18n, permissionChecker, eventBus, notification,
|
||||
managementUIState, managementViewClientCriterion, targetManagement, deploymentManagement, uiproperties,
|
||||
eventbus, entityFactory, uinotification, tagManagement, distributionSetManagement, uiExecutor);
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.eclipse.hawkbit.repository.model.TargetWithActionStatus;
|
||||
import org.eclipse.hawkbit.ui.common.UserDetailsFormatter;
|
||||
import org.eclipse.hawkbit.ui.components.ProxyTarget;
|
||||
import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
@@ -106,9 +105,9 @@ public class RolloutGroupTargetsBeanQuery extends AbstractBeanQuery<ProxyTarget>
|
||||
prxyTarget.setName(targ.getName());
|
||||
prxyTarget.setDescription(targ.getDescription());
|
||||
prxyTarget.setControllerId(targ.getControllerId());
|
||||
prxyTarget.setInstallationDate(targ.getTargetInfo().getInstallationDate());
|
||||
prxyTarget.setAddress(targ.getTargetInfo().getAddress());
|
||||
prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery());
|
||||
prxyTarget.setInstallationDate(targ.getInstallationDate());
|
||||
prxyTarget.setAddress(targ.getAddress());
|
||||
prxyTarget.setLastTargetQuery(targ.getLastTargetQuery());
|
||||
prxyTarget.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(targ.getLastModifiedAt()));
|
||||
prxyTarget.setCreatedDate(SPDateTimeUtil.getFormattedDate(targ.getCreatedAt()));
|
||||
prxyTarget.setCreatedAt(targ.getCreatedAt());
|
||||
@@ -117,13 +116,8 @@ public class RolloutGroupTargetsBeanQuery extends AbstractBeanQuery<ProxyTarget>
|
||||
if (targetWithActionStatus.getStatus() != null) {
|
||||
prxyTarget.setStatus(targetWithActionStatus.getStatus());
|
||||
}
|
||||
prxyTarget.setLastTargetQuery(targ.getTargetInfo().getLastTargetQuery());
|
||||
prxyTarget.setTargetInfo(targ.getTargetInfo());
|
||||
prxyTarget.setLastTargetQuery(targ.getLastTargetQuery());
|
||||
prxyTarget.setId(targ.getId());
|
||||
if (targ.getAssignedDistributionSet() != null) {
|
||||
prxyTarget.setAssignedDistNameVersion(HawkbitCommonUtil.getFormattedNameVersion(
|
||||
targ.getAssignedDistributionSet().getName(), targ.getAssignedDistributionSet().getVersion()));
|
||||
}
|
||||
return prxyTarget;
|
||||
}
|
||||
|
||||
|
||||
1
pom.xml
1
pom.xml
@@ -107,6 +107,7 @@
|
||||
<!-- Spring boot version overrides (should be reviewed with every boot upgrade) - START -->
|
||||
<!-- Newer versions needed than defined in Boot -->
|
||||
<spring-hateoas.version>0.23.0.RELEASE</spring-hateoas.version>
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
<!-- Older versions needed than defined in Boot -->
|
||||
<!-- Incompatible changes in 2.2 -->
|
||||
<json-path.version>2.0.0</json-path.version>
|
||||
|
||||
Reference in New Issue
Block a user