Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Update to support NXRM 3.15 #25

Merged
merged 5 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
language: java

jdk:
- openjdk8
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Nexus Repository Google Cloud Storage Blobstore
[![Build Status](https://travis-ci.org/sonatype-nexus-community/nexus-blobstore-google-cloud.svg?branch=master)](https://travis-ci.org/sonatype-nexus-community/nexus-blobstore-google-cloud) [![Join the chat at https://gitter.im/sonatype/nexus-developers](https://badges.gitter.im/sonatype/nexus-developers.svg)](https://gitter.im/sonatype/nexus-developers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

This project adds [Google Cloud Object Storage](https://cloud.google.com/storage/) backed blobstores to Sonatype Nexus
Repository 3.14 and later. It allows Nexus Repository to store the components and assets in Google Cloud instead of a
Repository 3.15 and later. It allows Nexus Repository to store the components and assets in Google Cloud instead of a
local filesystem.

Contribution Guidelines
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>org.sonatype.nexus.plugins</groupId>
<artifactId>nexus-plugins</artifactId>
<version>3.14.0-04</version>
<version>3.15.2-01</version>
</parent>

<artifactId>nexus-blobstore-google-cloud</artifactId>
Expand Down Expand Up @@ -76,6 +76,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-repository</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.sonatype.nexus.blobstore.gcloud.internal;

import org.sonatype.nexus.blobstore.AttributesLocation;

import com.google.cloud.storage.BlobInfo;

import static com.google.common.base.Preconditions.checkNotNull;

public class GoogleAttributesLocation
implements AttributesLocation
{
private final String key;
private final String fullPath;

public GoogleAttributesLocation(final BlobInfo blobInfo) {
checkNotNull(blobInfo);
this.key = checkNotNull(blobInfo.getName());
this.fullPath = key.substring(key.lastIndexOf('/') + 1);
}

@Override
public String getFileName() {
return this.fullPath;
}

@Override
public String getFullPath() {
return key;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,79 +13,26 @@
package org.sonatype.nexus.blobstore.gcloud.internal;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;

import org.sonatype.nexus.blobstore.api.BlobAttributes;
import org.sonatype.nexus.blobstore.BlobAttributesSupport;
import org.sonatype.nexus.blobstore.api.BlobMetrics;

import com.google.cloud.storage.Bucket;
import org.joda.time.DateTime;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.sonatype.nexus.blobstore.api.BlobAttributesConstants.CONTENT_SIZE_ATTRIBUTE;
import static org.sonatype.nexus.blobstore.api.BlobAttributesConstants.CREATION_TIME_ATTRIBUTE;
import static org.sonatype.nexus.blobstore.api.BlobAttributesConstants.DELETED_ATTRIBUTE;
import static org.sonatype.nexus.blobstore.api.BlobAttributesConstants.DELETED_REASON_ATTRIBUTE;
import static org.sonatype.nexus.blobstore.api.BlobAttributesConstants.HEADER_PREFIX;
import static org.sonatype.nexus.blobstore.api.BlobAttributesConstants.SHA1_HASH_ATTRIBUTE;

public class GoogleCloudBlobAttributes
implements BlobAttributes
extends BlobAttributesSupport<GoogleCloudPropertiesFile>
{
private Map<String, String> headers;

private BlobMetrics metrics;

private boolean deleted = false;

private String deletedReason;

private final GoogleCloudPropertiesFile propertiesFile;

public GoogleCloudBlobAttributes(final Bucket bucket, final String key) {
checkNotNull(key);
checkNotNull(bucket);
this.propertiesFile = new GoogleCloudPropertiesFile(bucket, key);
super(new GoogleCloudPropertiesFile(bucket, key), null, null);
}

public GoogleCloudBlobAttributes(final Bucket bucket, final String key, final Map<String, String> headers,
final BlobMetrics metrics) {
this(bucket, key);
this.headers = checkNotNull(headers);
this.metrics = checkNotNull(metrics);
}

@Override
public Map<String, String> getHeaders() {
return headers;
}

@Override
public BlobMetrics getMetrics() {
return metrics;
}

@Override
public boolean isDeleted() {
return deleted;
}

@Override
public void setDeleted(final boolean deleted) {
this.deleted = deleted;
}

@Override
public void setDeletedReason(final String deletedReason) {
this.deletedReason = deletedReason;
}

@Override
public String getDeletedReason() {
return deletedReason != null ? deletedReason : "No reason supplied";
super(new GoogleCloudPropertiesFile(bucket, key), checkNotNull(headers), checkNotNull(metrics));
}

public boolean load() throws IOException {
Expand All @@ -101,55 +48,4 @@ public void store() throws IOException {
writeTo(propertiesFile);
propertiesFile.store();
}

@Override
public Properties getProperties() {
return new Properties(propertiesFile);
}

@Override
public void updateFrom(final BlobAttributes blobAttributes) {
headers = blobAttributes.getHeaders();
metrics = blobAttributes.getMetrics();
deleted = blobAttributes.isDeleted();
deletedReason = blobAttributes.getDeletedReason();
}

private void readFrom(Properties properties) {
headers = new HashMap<>();
for (Entry<Object, Object> property : properties.entrySet()) {
String key = (String) property.getKey();
if (key.startsWith(HEADER_PREFIX)) {
headers.put(key.substring(HEADER_PREFIX.length()), String.valueOf(property.getValue()));
}
}

metrics = new BlobMetrics(
new DateTime(Long.parseLong(properties.getProperty(CREATION_TIME_ATTRIBUTE))),
properties.getProperty(SHA1_HASH_ATTRIBUTE),
Long.parseLong(properties.getProperty(CONTENT_SIZE_ATTRIBUTE)));

deleted = properties.containsKey(DELETED_ATTRIBUTE);
deletedReason = properties.getProperty(DELETED_REASON_ATTRIBUTE);
}

private Properties writeTo(final Properties properties) {
for (Entry<String, String> header : getHeaders().entrySet()) {
properties.put(HEADER_PREFIX + header.getKey(), header.getValue());
}
BlobMetrics blobMetrics = getMetrics();
properties.setProperty(SHA1_HASH_ATTRIBUTE, blobMetrics.getSha1Hash());
properties.setProperty(CONTENT_SIZE_ATTRIBUTE, Long.toString(blobMetrics.getContentSize()));
properties.setProperty(CREATION_TIME_ATTRIBUTE, Long.toString(blobMetrics.getCreationTime().getMillis()));

if (deleted) {
properties.put(DELETED_ATTRIBUTE, Boolean.toString(deleted));
properties.put(DELETED_REASON_ATTRIBUTE, getDeletedReason());
}
else {
properties.remove(DELETED_ATTRIBUTE);
properties.remove(DELETED_REASON_ATTRIBUTE);
}
return properties;
}
}
Loading