feat: allow a target to set offline assigned distribution set (#1620)

* feat: allow a target to set offline assigned distribution set

Signed-off-by: Florian Bezannier <florian.bezannier@hotmail.fr>

* refacto: apply @avgustinmm recommendation

* docs: Mark update offline API as experimental

---------

Signed-off-by: Florian Bezannier <florian.bezannier@hotmail.fr>
This commit is contained in:
Florian BEZANNIER
2024-08-01 10:51:31 +02:00
committed by GitHub
parent aa8ab69c1f
commit 0013750f78
10 changed files with 235 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.ddi.json.model.DdiActionFeedback;
import org.eclipse.hawkbit.ddi.json.model.DdiConfirmationFeedback;
import org.eclipse.hawkbit.ddi.json.model.DdiAssignedVersion;
import org.eclipse.hawkbit.ddi.json.model.DdiProgress;
import org.eclipse.hawkbit.ddi.json.model.DdiResult;
import org.eclipse.hawkbit.ddi.json.model.DdiStatus;
@@ -71,6 +72,8 @@ public abstract class AbstractDDiApiIntegrationTest extends AbstractRestIntegrat
protected static final String DEPLOYMENT_BASE = CONTROLLER_BASE + "/deploymentBase/{actionId}";
protected static final String CANCEL_ACTION = CONTROLLER_BASE + "/cancelAction/{actionId}";
protected static final String INSTALLED_BASE = CONTROLLER_BASE + "/installedBase/{actionId}";
protected static final String INSTALLED_BASE_ROOT = CONTROLLER_BASE + "/installedBase";
protected static final String DEPLOYMENT_FEEDBACK = DEPLOYMENT_BASE + "/feedback";
protected static final String CANCEL_FEEDBACK = CANCEL_ACTION + "/feedback";
@@ -134,6 +137,13 @@ public abstract class AbstractDDiApiIntegrationTest extends AbstractRestIntegrat
statusMatcher);
}
protected ResultActions postInstalledBase(final String controllerId, final String content,
final ResultMatcher statusMatcher) throws Exception {
return mvc.perform(post(INSTALLED_BASE_ROOT, tenantAware.getCurrentTenant(), controllerId)
.content(content.getBytes()).contentType(MediaType.APPLICATION_JSON_UTF8))
.andDo(MockMvcResultPrinter.print()).andExpect(statusMatcher);
}
protected ResultActions postDeploymentFeedback(final MediaType mediaType, final String controllerId,
final Long actionId, final byte[] content, final ResultMatcher statusMatcher) throws Exception {
return mvc
@@ -360,6 +370,10 @@ public abstract class AbstractDDiApiIntegrationTest extends AbstractRestIntegrat
return objectMapper.writeValueAsString(new DdiConfirmationFeedback(confirmation, code, messages));
}
protected String getJsonInstalledBase(String name, String version) throws JsonProcessingException {
return objectMapper.writeValueAsString(new DdiAssignedVersion(name, version));
}
protected static ObjectMapper getMapper(){
return objectMapper;
}

View File

@@ -102,6 +102,37 @@ public class DdiInstalledBaseTest extends AbstractDDiApiIntegrationTest {
String.valueOf(softwareModuleId));
}
@Test
@Description("Ensure that assigned version is self assigned version")
public void installedVersion() throws Exception {
final Target target = createTargetAndAssertNoActiveActions();
final DistributionSet ds = testdataFactory.createDistributionSet("");
// update assigned version
postInstalledBase(target.getControllerId(),getJsonInstalledBase(ds.getName(),ds.getVersion()),status()
.isCreated());
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get().getId())
.isEqualTo(ds.getId());
// update assigned version while version already assigned
postInstalledBase(target.getControllerId(),getJsonInstalledBase(ds.getName(),ds.getVersion()),status().isOk());
}
@Test
@Description("Ensure that installedVersion is version self assigned")
public void installedVersionNotExist() throws Exception {
final Target target = createTargetAndAssertNoActiveActions();
final String dsName = "unknown";
final String dsVersion = "1.0.0";
// get installed base
postInstalledBase(target.getControllerId(),getJsonInstalledBase(dsName,dsVersion),status().isNotFound());
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).isEmpty()).isTrue();
}
@Test
@Description("Test several deployments to a controller. Checks that action is represented as installedBase after installation.")
public void deploymentSeveralActionsInInstalledBase() throws Exception {