vivekshresta commented on a change in pull request #260:
URL: https://github.com/apache/airavata/pull/260#discussion_r478818511
##########
File path:
airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
##########
@@ -692,6 +695,80 @@ public String generateAndRegisterSSHKeys(AuthzToken
authzToken, String descripti
}
}
+ @Override
+ public void validateStorageLimit(AuthzToken authzToken, ExperimentModel
experiment, String storageResourceId)
+ throws InvalidRequestException, AiravataClientException,
AiravataSystemException, TException {
+ String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
+ RegistryService.Client regClient = registryClientPool.getResource();
+ try {
+ StoragePreference storagePreference =
regClient.getGatewayStoragePreference(gatewayId, storageResourceId);
+ if(storagePreference.getUserStorageQuota() == 0)
+ return; //quota isn't configured
+
+ String groupResourceProfileId =
experiment.getUserConfigurationData().getGroupResourceProfileId();
+ if (groupResourceProfileId == null) {
+ logger.error("Experiment not configured with a Group Resource
Profile: {}", experiment.getExperimentId());
+ AiravataSystemException exception = new
AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage("Experiment not configured with a Group
Resource Profile: " + experiment.getExperimentId());
+ throw exception;
+ }
+
+ GatewayResourceProfile gatewayResourceProfile =
regClient.getGatewayResourceProfile(gatewayId);
+ String token;
+
if(isValid(storagePreference.getResourceSpecificCredentialStoreToken()))
+ token =
storagePreference.getResourceSpecificCredentialStoreToken();
+ else
+ token = gatewayResourceProfile.getCredentialStoreToken();
+
+ StorageResourceAdaptor adaptor =
AdaptorSupportImpl.getInstance().fetchStorageAdaptor(
+ gatewayId,
+ storageResourceId,
+ DataMovementProtocol.SCP,
+ token,
+ storagePreference.getLoginUserName());
+ String experimentDataDir =
experiment.getUserConfigurationData().getExperimentDataDir();
+ String userDirectory = getUserDirectory(experimentDataDir);
+
+ //shouldn't retrieve size in giga bytes since the du -s command
rounds off the value to a higher bound.
+ CommandOutput output = adaptor.executeCommand("du -sm",
userDirectory);
+ if(!output.getStdError().isEmpty()) {
+ logger.error("The experiment data directory + " +
experimentDataDir + " configured on the experiment is wrong.");
+ AiravataSystemException exception = new
AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage("The experiment data directory + " +
experimentDataDir + " configured on the experiment is wrong.");
+ throw exception;
+ }
+
+ double userDirectorySize =
Double.parseDouble(output.getStdOut().substring(0, output.getStdOut().length()
- 2).trim())/1024.0;
Review comment:
> And do you think that the output format is same for all operating
systems (Linux)? If not, your algorithm might be wrong
Did not know about such a use case. Will test it and update it if necessary.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]