Removed external artifact from repository.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -32,7 +32,7 @@ import org.eclipse.hawkbit.ddi.json.model.DdiPolling;
|
||||
import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.hateoas.Link;
|
||||
@@ -85,13 +85,13 @@ public final class DataConversionHelper {
|
||||
final org.eclipse.hawkbit.repository.model.SoftwareModule module,
|
||||
final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement) {
|
||||
|
||||
return module.getLocalArtifacts().stream()
|
||||
return module.getArtifacts().stream()
|
||||
.map(artifact -> createArtifact(target, artifactUrlHandler, artifact, systemManagement))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static DdiArtifact createArtifact(final Target target, final ArtifactUrlHandler artifactUrlHandler,
|
||||
final LocalArtifact artifact, final SystemManagement systemManagement) {
|
||||
final Artifact artifact, final SystemManagement systemManagement) {
|
||||
final DdiArtifact file = new DdiArtifact();
|
||||
file.setHashes(new DdiArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash()));
|
||||
file.setFilename(artifact.getFilename());
|
||||
@@ -157,8 +157,8 @@ public final class DataConversionHelper {
|
||||
return result;
|
||||
}
|
||||
|
||||
static void writeMD5FileResponse(final String fileName, final HttpServletResponse response,
|
||||
final LocalArtifact artifact) throws IOException {
|
||||
static void writeMD5FileResponse(final String fileName, final HttpServletResponse response, final Artifact artifact)
|
||||
throws IOException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(artifact.getMd5Hash());
|
||||
builder.append(" ");
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
|
||||
import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper;
|
||||
@@ -71,7 +71,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
|
||||
@Override
|
||||
public ResponseEntity<InputStream> downloadArtifactByFilename(@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("fileName") final String fileName, @AuthenticationPrincipal final String targetid) {
|
||||
final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName);
|
||||
final List<Artifact> foundArtifacts = artifactManagement.findArtifactByFilename(fileName);
|
||||
|
||||
if (foundArtifacts.isEmpty()) {
|
||||
LOG.warn("Software artifact with name {} could not be found.", fileName);
|
||||
@@ -82,13 +82,13 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
|
||||
LOG.warn("Software artifact name {} is not unique. We will use the first entry.", fileName);
|
||||
}
|
||||
ResponseEntity<InputStream> result;
|
||||
final LocalArtifact artifact = foundArtifacts.get(0);
|
||||
final Artifact artifact = foundArtifacts.get(0);
|
||||
|
||||
final String ifMatch = requestResponseContextHolder.getHttpServletRequest().getHeader("If-Match");
|
||||
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
|
||||
result = new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
|
||||
} else {
|
||||
final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact);
|
||||
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
|
||||
|
||||
// we set a download status only if we are aware of the
|
||||
// targetid, i.e. authenticated and not anonymous
|
||||
@@ -112,7 +112,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
|
||||
@Override
|
||||
public ResponseEntity<Void> downloadArtifactMD5ByFilename(@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("fileName") final String fileName) {
|
||||
final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName);
|
||||
final List<Artifact> foundArtifacts = artifactManagement.findArtifactByFilename(fileName);
|
||||
|
||||
if (foundArtifacts.isEmpty()) {
|
||||
LOG.warn("Softeare artifact with name {} could not be found.", fileName);
|
||||
@@ -133,7 +133,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
|
||||
}
|
||||
|
||||
private ActionStatus checkAndReportDownloadByTarget(final HttpServletRequest request, final String targetid,
|
||||
final LocalArtifact artifact) {
|
||||
final Artifact artifact) {
|
||||
final Target target = controllerManagement.updateLastTargetQuery(targetid,
|
||||
IpUtil.getClientIpFromRequest(request, securityProperties));
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
|
||||
@@ -154,9 +154,9 @@ public class DdiRootController implements DdiRootControllerRestApi {
|
||||
// Exception squid:S3655 - Optional access is checked in checkModule
|
||||
// subroutine
|
||||
@SuppressWarnings("squid:S3655")
|
||||
final LocalArtifact artifact = module.getLocalArtifactByFilename(fileName).get();
|
||||
final Artifact artifact = module.getArtifactByFilename(fileName).get();
|
||||
|
||||
final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact);
|
||||
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
|
||||
|
||||
final String ifMatch = requestResponseContextHolder.getHttpServletRequest().getHeader("If-Match");
|
||||
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
|
||||
@@ -196,7 +196,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
|
||||
}
|
||||
|
||||
private static boolean checkModule(final String fileName, final SoftwareModule module) {
|
||||
return null == module || !module.getLocalArtifactByFilename(fileName).isPresent();
|
||||
return null == module || !module.getArtifactByFilename(fileName).isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,7 +219,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
|
||||
|
||||
try {
|
||||
DataConversionHelper.writeMD5FileResponse(fileName, requestResponseContextHolder.getHttpServletResponse(),
|
||||
module.getLocalArtifactByFilename(fileName).get());
|
||||
module.getArtifactByFilename(fileName).get());
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Failed to stream MD5 File", e);
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.eclipse.hawkbit.repository.model.Action;
|
||||
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.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB;
|
||||
@@ -99,7 +98,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
|
||||
// create artifact
|
||||
final byte random[] = RandomUtils.nextBytes(5 * 1024);
|
||||
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1", false);
|
||||
|
||||
// no artifact available
|
||||
@@ -193,7 +192,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
// test now consistent data to test allowed methods
|
||||
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1", false);
|
||||
|
||||
mvc.perform(
|
||||
@@ -268,7 +267,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
|
||||
// create artifact
|
||||
final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE);
|
||||
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1", false);
|
||||
|
||||
// download fails as artifact is not yet assigned
|
||||
@@ -309,7 +308,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
|
||||
// create artifact
|
||||
final byte random[] = RandomUtils.nextBytes(5 * 1024);
|
||||
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1", false);
|
||||
|
||||
// download
|
||||
@@ -349,8 +348,8 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
|
||||
// create artifact
|
||||
final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE);
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(),
|
||||
"file1.tar.bz2", false);
|
||||
|
||||
// download fails as artifact is not yet assigned to target
|
||||
deploymentManagement.assignDistributionSet(ds, targets);
|
||||
@@ -383,7 +382,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
|
||||
// create artifact
|
||||
final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE);
|
||||
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1", false);
|
||||
|
||||
// download fails as artifact is not yet assigned to target
|
||||
@@ -435,7 +434,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
|
||||
// create artifact
|
||||
final byte random[] = RandomUtils.nextBytes(resultLength);
|
||||
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1", false);
|
||||
|
||||
assertThat(random.length).isEqualTo(resultLength);
|
||||
@@ -539,7 +538,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
|
||||
// create artifact
|
||||
final byte random[] = RandomUtils.nextBytes(5 * 1024);
|
||||
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false);
|
||||
|
||||
// download fails as artifact is not yet assigned to target
|
||||
@@ -559,7 +558,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
|
||||
|
||||
// create artifact
|
||||
final byte random[] = RandomUtils.nextBytes(5 * 1024);
|
||||
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false);
|
||||
|
||||
// download
|
||||
|
||||
@@ -32,8 +32,8 @@ import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.RepositoryModelConstants;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
@@ -87,7 +87,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
|
||||
tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0)));
|
||||
|
||||
testdataFactory.createLocalArtifacts(softwareModuleId);
|
||||
testdataFactory.createArtifacts(softwareModuleId);
|
||||
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts",
|
||||
tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -107,9 +107,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
|
||||
|
||||
final byte random[] = RandomUtils.nextBytes(5 * 1024);
|
||||
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "test1", false);
|
||||
final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "test1.signature", false);
|
||||
|
||||
final Target savedTarget = targetManagement.createTarget(target);
|
||||
@@ -270,9 +270,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
|
||||
|
||||
final byte random[] = RandomUtils.nextBytes(5 * 1024);
|
||||
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "test1", false);
|
||||
final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "test1.signature", false);
|
||||
|
||||
final Target savedTarget = targetManagement.createTarget(target);
|
||||
@@ -394,9 +394,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
|
||||
|
||||
final byte random[] = RandomUtils.nextBytes(5 * 1024);
|
||||
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "test1", false);
|
||||
final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
ds.findFirstModuleByType(osType).getId(), "test1.signature", false);
|
||||
|
||||
final Target savedTarget = targetManagement.createTarget(target);
|
||||
|
||||
Reference in New Issue
Block a user