Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bytes length for localEGA profile #135

Merged
merged 3 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- sleep 90
- cd ../ega-data-api-it
script:
- mvn test -Dtest=!DataedgeIntgTest,!MetadataControllerIntgTest
- mvn test
- stage: image build
script: ./extras/travis_push_docker_hub.sh

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2016 ELIXIR EGA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.elixir.ega.ebi.dataedge.service;

import eu.elixir.ega.ebi.shared.dto.File;

/**
* @author amohan
*/
public interface FileLengthService {

long getContentLength(File reqFile, String destinationFormat, long startCoordinate, long endCoordinate);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2016 ELIXIR EGA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.elixir.ega.ebi.dataedge.service.internal;

import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import eu.elixir.ega.ebi.dataedge.service.FileLengthService;
import eu.elixir.ega.ebi.shared.dto.File;

/**
* @author amohan
*/
@Service
@Primary
@Profile("!LocalEGA")
public class FileLengthServiceImpl implements FileLengthService {

@Override
public long getContentLength(File reqFile, String destinationFormat, long startCoordinate, long endCoordinate) {
long length = 0;

// EncryptionFormat
// If destinationFormat is encrypted then we add extra 16 byte to store the IV.
int prefix = 16;
if (destinationFormat.equalsIgnoreCase("plain"))
prefix = 0;

// Range specified?
// The AES encrypted data has a 16 byte random IV at the start, so to
// get the correct (raw) file length we need to remove this 16 byte
// prefix.
if (startCoordinate > 0 || endCoordinate > 0) {
length = endCoordinate - startCoordinate;
} else {
length = reqFile.getFileSize() - 16;
}

return (length + prefix);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2016 ELIXIR EGA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.elixir.ega.ebi.dataedge.service.internal;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import eu.elixir.ega.ebi.dataedge.service.FileLengthService;
import eu.elixir.ega.ebi.shared.dto.File;

/**
* @author amohan
*/
@Service
@Profile("LocalEGA")
public class LocalEGAFileLengthServiceImpl implements FileLengthService {

@Override
public long getContentLength(File reqFile, String destinationFormat, long startCoordinate, long endCoordinate) {
long length = 0;

if (startCoordinate > 0 || endCoordinate > 0) {
length = endCoordinate - startCoordinate;
} else {
length = reqFile.getFileSize();
omllobet marked this conversation as resolved.
Show resolved Hide resolved
}

return length;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import eu.elixir.ega.ebi.shared.dto.EventEntry;
import eu.elixir.ega.ebi.shared.service.DownloaderLogService;
import eu.elixir.ega.ebi.shared.service.FileInfoService;
import eu.elixir.ega.ebi.dataedge.service.FileLengthService;
import eu.elixir.ega.ebi.dataedge.service.FileService;
import eu.elixir.ega.ebi.shared.dto.File;
import eu.elixir.ega.ebi.shared.dto.FileIndexFile;
Expand Down Expand Up @@ -102,6 +103,9 @@ public class RemoteFileServiceImpl implements FileService {

@Autowired
private FileInfoService fileInfoService;

@Autowired
private FileLengthService fileLengthService;

@Override
//@HystrixCommand
Expand Down Expand Up @@ -147,12 +151,12 @@ public void getFile(String fileId,
String headerValue = dlIdentifier.toString();
response = setHeaders(response, headerValue);

long fileLength = fileLengthService.getContentLength(reqFile, destinationFormat, startCoordinate, endCoordinate);

// Content Length of response (if available)
response.setContentLengthLong(getContentLength(reqFile, destinationFormat, startCoordinate, endCoordinate));
response.setContentLengthLong(fileLength);

// If byte range, set response 206
long fileLength = reqFile.getFileSize();
if (destinationFormat.equalsIgnoreCase("plain")) fileLength -= 16;
if (startCoordinate > 0 || endCoordinate > 0) {
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
response.addHeader("Content-Range", "bytes " + startCoordinate +
Expand Down Expand Up @@ -275,8 +279,8 @@ public void getFileHead(String fileId,
response = setHeaders(response, headerValue);

// Content Length of response (if available)
response.setContentLengthLong(getContentLength(reqFile, destinationFormat, 0, 0));
response.addHeader("X-Content-Length", String.valueOf(getContentLength(reqFile, destinationFormat, 0, 0)));
response.setContentLengthLong(fileLengthService.getContentLength(reqFile, destinationFormat, 0, 0));
response.addHeader("X-Content-Length", String.valueOf(fileLengthService.getContentLength(reqFile, destinationFormat, 0, 0)));
}
}

Expand Down Expand Up @@ -773,22 +777,4 @@ private VariantContext filterMe(VariantContext context, List<String> fields, Lis
return context;
}

private long getContentLength(File reqFile, String destinationFormat, long startCoordinate, long endCoordinate) {
long length = 0;

// EncryptionFormat
int prefix = 16;
if (destinationFormat.equalsIgnoreCase("plain"))
prefix = 0;

// Range specified?
if (startCoordinate > 0 || endCoordinate > 0) {
length = endCoordinate - startCoordinate;
} else {
length = reqFile.getFileSize() - 16;
}

return (length + prefix);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import eu.elixir.ega.ebi.dataedge.config.InternalErrorException;
import eu.elixir.ega.ebi.dataedge.dto.*;
import eu.elixir.ega.ebi.dataedge.service.FileLengthService;
import eu.elixir.ega.ebi.shared.service.DownloaderLogService;
import eu.elixir.ega.ebi.shared.service.FileInfoService;
import eu.elixir.ega.ebi.shared.dto.File;
Expand Down Expand Up @@ -102,6 +103,9 @@ public class RemoteFileServiceImplTest {

@Mock
private FileInfoService fileInfoService;

@Mock
private FileLengthService fileLengthService;

/**
* Test class for
Expand Down
2 changes: 1 addition & 1 deletion extras/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- "9058:9058"
- "5059:5059"
environment:
- SPRING_PROFILES_ACTIVE=no-oss
- SPRING_PROFILES_ACTIVE=no-oss,LocalEGA
- server.port=9058
- JWTKEY=${JWTKEY}
- FILEDATABASE.listOfServers=filedatabase:9051
Expand Down