Skip to content

Commit

Permalink
Merge pull request #322 from bsinno/fix_optimize_repository
Browse files Browse the repository at this point in the history
Removed external artifact from repository.
  • Loading branch information
kaizimmerm authored Oct 27, 2016
2 parents 2488995 + 1d0028c commit b7f5bf3
Show file tree
Hide file tree
Showing 66 changed files with 601 additions and 1,471 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
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;
Expand Down Expand Up @@ -85,13 +85,13 @@ public static List<DdiArtifact> createArtifacts(final Target target,
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());
Expand Down Expand Up @@ -157,8 +157,8 @@ private static int calculateEtag(final Action action) {
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(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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;
Expand Down Expand Up @@ -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);
Expand All @@ -82,13 +82,13 @@ public ResponseEntity<InputStream> downloadArtifactByFilename(@PathVariable("ten
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
Expand All @@ -112,7 +112,7 @@ public ResponseEntity<InputStream> downloadArtifactByFilename(@PathVariable("ten
@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);
Expand All @@ -133,7 +133,7 @@ public ResponseEntity<Void> downloadArtifactMD5ByFilename(@PathVariable("tenant"
}

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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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;
Expand Down Expand Up @@ -154,9 +154,9 @@ public ResponseEntity<InputStream> downloadArtifact(@PathVariable("tenant") fina
// 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())) {
Expand Down Expand Up @@ -196,7 +196,7 @@ private ActionStatus checkAndLogDownload(final HttpServletRequest request, final
}

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
Expand All @@ -219,7 +219,7 @@ public ResponseEntity<Void> downloadArtifactMd5(@PathVariable("tenant") final St

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB;
Expand Down Expand Up @@ -99,7 +98,7 @@ public void invalidRequestsOnArtifactResource() throws Exception {

// 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
Expand Down Expand Up @@ -193,7 +192,7 @@ public void invalidRequestsOnArtifactResourceByName() throws Exception {
.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(
Expand Down Expand Up @@ -268,7 +267,7 @@ public void downloadArtifactThroughFileName() throws Exception {

// 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
Expand Down Expand Up @@ -309,7 +308,7 @@ public void downloadMd5sumThroughControllerApi() throws Exception {

// 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
Expand Down Expand Up @@ -349,8 +348,8 @@ public void downloadArtifactByNameFailsIfNotAuthenticated() throws Exception {

// 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);
Expand Down Expand Up @@ -383,7 +382,7 @@ public void downloadArtifactByNameByNamedController() throws Exception {

// 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
Expand Down Expand Up @@ -435,7 +434,7 @@ public void rangeDownloadArtifactByName() throws Exception {

// 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);
Expand Down Expand Up @@ -539,7 +538,7 @@ public void faildDownloadArtifactByNameIfAuthenticationMissing() throws Exceptio

// 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
Expand All @@ -559,7 +558,7 @@ public void downloadMd5sumFileByName() throws Exception {

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
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;
Expand Down Expand Up @@ -87,7 +87,7 @@ public void artifactsExists() throws Exception {
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())
Expand All @@ -107,9 +107,9 @@ public void deplomentForceAction() throws Exception {
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);
Expand Down Expand Up @@ -270,9 +270,9 @@ public void deplomentAttemptAction() throws Exception {
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);
Expand Down Expand Up @@ -394,9 +394,9 @@ public void deplomentAutoForceAction() throws Exception {
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);
Expand Down
Loading

0 comments on commit b7f5bf3

Please sign in to comment.