Skip to content
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
2 changes: 1 addition & 1 deletion extensions-core/azure-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.89</minimum>
<minimum>0.88</minimum>
</limit>
<limit>
<counter>COMPLEXITY</counter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.validation.constraints.NotNull;

/**
* Stores the configuration for segments written to Azure deep storage
*/
public class AzureDataSegmentConfig
{
@JsonProperty
@NotNull
private String container;

@JsonProperty
@NotNull
private String prefix = "";

public void setContainer(String container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.base.Predicates;
import com.google.inject.Inject;
import com.microsoft.azure.storage.StorageException;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.MapUtils;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.segment.loading.DataSegmentKiller;
Expand Down Expand Up @@ -88,6 +89,10 @@ public void kill(DataSegment segment) throws SegmentLoadingException
@Override
public void killAll() throws IOException
{
if (segmentConfig.getContainer() == null || segmentConfig.getPrefix() == null) {
throw new ISE(
"Cannot delete all segment files since Azure Deep Storage since druid.azure.container and druid.azure.prefix are not both set.");
}
log.info(
"Deleting all segment files from Azure storage location [bucket: '%s' prefix: '%s']",
segmentConfig.getContainer(),
Expand All @@ -109,5 +114,4 @@ public void killAll() throws IOException
throw new IOException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.ImmutableMap;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.StorageExtendedErrorInformation;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.Intervals;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.segment.loading.SegmentLoadingException;
Expand Down Expand Up @@ -148,6 +149,33 @@ public void test_kill_URISyntaxException_throwsException()
verifyAll();
}

@Test
public void test_killAll_segmentConfigWithNullContainerAndPrefix_throwsISEException() throws Exception
{
EasyMock.expect(segmentConfig.getContainer()).andReturn(null).atLeastOnce();
EasyMock.expect(segmentConfig.getPrefix()).andReturn(null).anyTimes();

boolean thrownISEException = false;

try {
AzureDataSegmentKiller killer = new AzureDataSegmentKiller(
segmentConfig,
inputDataConfig,
accountConfig,
azureStorage,
azureCloudBlobIterableFactory
);
EasyMock.replay(segmentConfig, inputDataConfig, accountConfig, azureStorage, azureCloudBlobIterableFactory);
killer.killAll();
}
catch (ISE e) {
thrownISEException = true;
}

Assert.assertTrue(thrownISEException);
EasyMock.verify(segmentConfig, inputDataConfig, accountConfig, azureStorage, azureCloudBlobIterableFactory);
}

@Test
public void test_killAll_noException_deletesAllSegments() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.validation.constraints.NotNull;

public class GoogleAccountConfig
{
@JsonProperty
@NotNull
private String bucket;

@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.api.client.http.HttpResponseException;
import com.google.common.base.Predicates;
import com.google.inject.Inject;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.MapUtils;
import org.apache.druid.java.util.common.RE;
import org.apache.druid.java.util.common.RetryUtils;
Expand Down Expand Up @@ -104,6 +105,10 @@ private void deleteIfPresent(String bucket, String path) throws IOException
@Override
public void killAll() throws IOException
{
if (accountConfig.getBucket() == null || accountConfig.getPrefix() == null) {
throw new ISE(
"Cannot delete all segment files from Google Deep Storage since druid.google.bucket and druid.google.prefix are not both set.");
}
LOG.info(
"Deleting all segment files from gs location [bucket: '%s' prefix: '%s']",
accountConfig.getBucket(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.api.services.storage.model.StorageObject;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.Intervals;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.segment.loading.DataSegmentKiller;
Expand Down Expand Up @@ -142,6 +143,29 @@ public void killRetryWithErrorTest() throws SegmentLoadingException, IOException
verifyAll();
}

@Test
public void test_killAll_accountConfigWithNullBucketAndPrefix_throwsISEException() throws IOException
{

EasyMock.expect(accountConfig.getBucket()).andReturn(null).atLeastOnce();
EasyMock.expect(accountConfig.getPrefix()).andReturn(null).anyTimes();

boolean thrownISEException = false;

try {
GoogleDataSegmentKiller killer = new GoogleDataSegmentKiller(storage, accountConfig, inputDataConfig);
EasyMock.replay(storage, inputDataConfig, accountConfig);

killer.killAll();
}
catch (ISE e) {
thrownISEException = true;
}

Assert.assertTrue(thrownISEException);
EasyMock.verify(accountConfig, inputDataConfig, storage);
}

@Test
public void test_killAll_noException_deletesAllTaskLogs() throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.amazonaws.AmazonServiceException;
import com.google.common.base.Predicates;
import com.google.inject.Inject;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.MapUtils;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.segment.loading.DataSegmentKiller;
Expand Down Expand Up @@ -82,6 +83,10 @@ public void kill(DataSegment segment) throws SegmentLoadingException
@Override
public void killAll() throws IOException
{
if (segmentPusherConfig.getBucket() == null || segmentPusherConfig.getBaseKey() == null) {
throw new ISE(
"Cannot delete all segment from S3 Deep Storage since druid.storage.bucket and druid.storage.baseKey are not both set.");
}
log.info("Deleting all segment files from s3 location [bucket: '%s' prefix: '%s']",
segmentPusherConfig.getBucket(), segmentPusherConfig.getBaseKey()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.amazonaws.services.s3.model.S3ObjectSummary;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.StringUtils;
import org.easymock.EasyMock;
import org.easymock.EasyMockRunner;
Expand Down Expand Up @@ -59,6 +60,30 @@ public class S3DataSegmentKillerTest extends EasyMockSupport

private S3DataSegmentKiller segmentKiller;

@Test
public void test_killAll_accountConfigWithNullBucketAndBaseKey_throwsISEException() throws IOException
{
EasyMock.expect(segmentPusherConfig.getBucket()).andReturn(null);
EasyMock.expectLastCall().atLeastOnce();
EasyMock.expect(segmentPusherConfig.getBaseKey()).andReturn(null);
EasyMock.expectLastCall().anyTimes();

boolean thrownISEException = false;

try {

EasyMock.replay(s3Client, segmentPusherConfig, inputDataConfig);

segmentKiller = new S3DataSegmentKiller(s3Client, segmentPusherConfig, inputDataConfig);
segmentKiller.killAll();
}
catch (ISE e) {
thrownISEException = true;
}
Assert.assertTrue(thrownISEException);
EasyMock.verify(s3Client, segmentPusherConfig, inputDataConfig);
}

@Test
public void test_killAll_noException_deletesAllSegments() throws IOException
{
Expand Down