Skip to content

Commit

Permalink
Further followup on CR-NAS-372.
Browse files Browse the repository at this point in the history
  • Loading branch information
jolf committed Apr 5, 2019
1 parent d79ad77 commit 8d4ebfd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
Expand Up @@ -33,10 +33,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import javax.jms.JMSException;


import org.bitrepository.access.AccessComponentFactory;
import org.bitrepository.access.getchecksums.BlockingGetChecksumsClient;
import org.bitrepository.access.getchecksums.GetChecksumsClient;
Expand Down Expand Up @@ -80,8 +80,8 @@
import org.bitrepository.protocol.security.PermissionStore;
import org.bitrepository.protocol.security.SecurityManager;
import org.bitrepository.settings.repositorysettings.Collection;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dk.netarkivet.common.exceptions.ArgumentNotValid;
import dk.netarkivet.common.exceptions.IOFailure;
Expand Down Expand Up @@ -149,13 +149,12 @@ public Bitrepository(File configDir, String bitmagKeyFilename, int maxStoreFailu
/** The authentication key used by the putfileClient. */
File privateKeyFile;
if (bitmagKeyFilename == null){
privateKeyFile = new File(configDir, "dummy-certificate.pem"); // This file should never exist
privateKeyFile = new File(configDir, UUID.randomUUID().toString()); // This file should never exist
} else {
privateKeyFile = new File(configDir, bitmagKeyFilename);
}
logger.info("keyfile: {}", privateKeyFile.getAbsolutePath());


logger.info("Initialising bitrepository settings.");
SettingsProvider settingsLoader =
new SettingsProvider(
Expand All @@ -166,7 +165,7 @@ public Bitrepository(File configDir, String bitmagKeyFilename, int maxStoreFailu
SettingsUtils.initialize(bitmagSettings);

logger.info("Initialising bitrepository security manager.");
// Mandatory,even if we point to a nonexisting file dummy-certificate.pem
// Mandatory,even if we point to a nonexisting keyfile
PermissionStore permissionStore = new PermissionStore();
MessageAuthenticator authenticator = new BasicMessageAuthenticator(permissionStore);
MessageSigner signer = new BasicMessageSigner();
Expand All @@ -176,11 +175,9 @@ public Bitrepository(File configDir, String bitmagKeyFilename, int maxStoreFailu
authenticator, signer, authorizer, permissionStore,
bitmagSettings.getComponentID());


logger.info("Getting bitrepository message bus");
bitMagMessageBus = ProtocolComponentFactory.getInstance().getMessageBus(
bitmagSettings, bitMagSecurityManager); // Is bitMagSecurityManager mandatory?

bitmagSettings, bitMagSecurityManager);

logger.info("Initialising bitrepository clients");
bitMagPutClient = ModifyComponentFactory.getInstance().retrievePutClient(
Expand Down Expand Up @@ -286,12 +283,12 @@ public File getFile(final String fileId, final String collectionId, final FilePa
// Note that this eventHandler is blocking
CompleteEventAwaiter eventHandler = new GetFileEventHandler(this.bitmagSettings, output);
output.debug("Initiating the GetFile conversation.");
String auditTrailInformation = "Retrieving package '" + fileId + "' from collection '" + collectionId + "' using pillar '" + usepillar + "'";
String auditTrailInformation = "Retrieving package '" + fileId + "' from collection '" + collectionId
+ "' using pillar '" + usepillar + "'";
logger.info(auditTrailInformation);
//bitMagGetClient.getFileFromFastestPillar(collectionId, fileId, filePart, fileUrl, eventHandler,
// auditTrailInformation);

bitMagGetClient.getFileFromSpecificPillar(collectionId, fileId, filePart, fileUrl, usepillar, eventHandler, auditTrailInformation);

bitMagGetClient.getFileFromSpecificPillar(collectionId, fileId, filePart, fileUrl, usepillar, eventHandler,
auditTrailInformation);

OperationEvent finalEvent = eventHandler.getFinish();
if(finalEvent.getEventType() == OperationEventType.COMPLETE) {
Expand All @@ -311,7 +308,8 @@ public File getFile(final String fileId, final String collectionId, final FilePa

/**
* Downloads the file from the URL defined in the conversation and deletes it from the fileExchange server.
* @throws IOException
* @param fileUrl The URL for the file to download.
* @throws IOException If an connection issue occur.
*/
private File downloadFile(URL fileUrl) throws IOException {
File outputFile = File.createTempFile("Extracted", null);
Expand Down Expand Up @@ -361,7 +359,6 @@ public boolean existsInCollection(String packageId, String collectionID) {

OutputHandler output = new DefaultOutputHandler(Bitrepository.class);

//GetFileIDsListFormatter outputFormatter = new GetFileIDsListFormatter(output);
GetFileIDsOutputFormatter outputFormatter = new GetFileIDsNoFormatter(output);
long timeout = BitrepositoryUtils.getClientTimeout(bitmagSettings);

Expand All @@ -377,11 +374,7 @@ public boolean existsInCollection(String packageId, String collectionID) {
* @param packageID A given package ID (if null, checksums for the whole collection is requested)
* @param collectionID A given collection ID
* @return a map with the results from the pillars
<<<<<<< HEAD
* @throws IOFailure If it fails to retrieve the checksums.
=======
* @throws IOFailure If it fails to retrieve checksums.
>>>>>>> 4cc7008f4620754fa82ca22dd2ae81bbe88625f1
*/
public Map<String, ChecksumsCompletePillarEvent> getChecksums(String packageID, String collectionID)
throws IOFailure {
Expand All @@ -395,7 +388,8 @@ public Map<String, ChecksumsCompletePillarEvent> getChecksums(String packageID,
}
BlockingGetChecksumsClient client = new BlockingGetChecksumsClient(bitMagGetChecksumsClient);
ChecksumSpecTYPE checksumSpec = ChecksumUtils.getDefault(bitmagSettings);
BlockingEventHandler eventhandler = new NetarchivesuiteBlockingEventHandler(collectionID, maxNumberOfFailingPillars);
BlockingEventHandler eventhandler = new NetarchivesuiteBlockingEventHandler(collectionID,
maxNumberOfFailingPillars);

try {
client.getChecksums(collectionID, null, packageID, checksumSpec, null, eventhandler, null);
Expand Down Expand Up @@ -443,18 +437,23 @@ public void shutdown() {
}

/**
* @return a set of known CollectionIDs
* @return The list of known CollectionIDs (and duplicates has been removed).
*/
public List<String> getKnownCollections() {
List<Collection> knownCollections = bitmagSettings.getRepositorySettings()
.getCollections().getCollection();
Set<String> collectionIDs = new HashSet<>();
for (Collection c: knownCollections) {
for (Collection c : knownCollections) {
collectionIDs.add(c.getID());
}
return new ArrayList<>(collectionIDs);
}

/**
* Retrieves the list of file ids in the given collection from the default pillar.
* @param collectionID The collection to retrieve the list of file ids from.
* @return The list of file ids.
*/
public List<String> getFileIds(String collectionID) {

OutputHandler output = new DefaultOutputHandler(Bitrepository.class);
Expand All @@ -476,7 +475,8 @@ public List<String> getFileIds(String collectionID) {
}
}

@Override public void close() throws Exception {
@Override
public void close() throws Exception {
this.shutdown();
}
}
Expand Up @@ -60,9 +60,9 @@ public static ChecksumDataForFileTYPE getValidationChecksum(File file, ChecksumS
}

/**
* Specify a checksum.
* @param checksumtype a given type of checksum
* @param salt A string to salt the checksum with (if null, no salting)
* Specify a checksum.
* @param checksumtype a given type of checksum
* @param salt A string to salt the checksum with (if null, no salting)
* @return The requested checksum spec
*/
public static ChecksumSpecTYPE getRequestChecksumSpec(ChecksumType checksumtype, String salt) {
Expand All @@ -83,6 +83,11 @@ public static String generateComponentID() {
return "NetarchivesuiteClient-" + hn + "-" + UUID.randomUUID();
}

/**
* Retrieves the FileExchange for this bitmag setup.
* @param bitmagSettings The settings.
* @return The FileExchange.
*/
static FileExchange getFileExchange(Settings bitmagSettings) {
return ProtocolComponentFactory.getInstance().getFileExchange(
bitmagSettings);
Expand Down

0 comments on commit 8d4ebfd

Please sign in to comment.