Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Jun 1, 2024
1 parent 5e6e4a2 commit ea2ecf5
Show file tree
Hide file tree
Showing 39 changed files with 785 additions and 538 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ lint: ## Run Apache Spotless linter

.PHONY: create-local-client
create-local-client: ## Create ResourceTracker local directory for client
@mkdir -p $(HOME)/.repoachiever/config
.PHONY: create-local-client
create-local-client: ## Create ResourceTracker local directory for client
@mkdir -p $(HOME)/.repoachiever/config/swap

.PHONY: create-local-api-server
create-local-api-server: ## Create ResourceTracker local directory for API Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,57 +103,6 @@ public List<RepositoryContentLocationUnitDto> retrieveLocations(
return result;
}

/**
* Checks if content location is present in content repository with the help of the given properties.
*
* @param location given content location.
* @param provider given content provider.
* @param credentials given content credentials.
* @return result of the check.
* @throws ContentValidationFailureException if content validation fails.
*/
public Boolean isContentLocationValid(
String location, Provider provider, CredentialsFieldsFull credentials) throws ContentValidationFailureException {
ProviderEntity rawProvider;

try {
rawProvider = providerRepository.findByName(provider.toString());
} catch (RepositoryOperationFailureException e) {
throw new ContentValidationFailureException(e.getMessage());
}

Optional<String> rawCredentials = RepositoryConfigurationHelper.getExternalCredentials(
provider, credentials.getExternal());

try {
if (!secretRepository.isPresentBySessionAndCredentials(
credentials.getInternal().getId(), rawCredentials)) {
return false;
}
} catch (RepositoryOperationFailureException e) {
throw new ContentValidationFailureException(e.getMessage());
}

SecretEntity secret;

try {
secret = secretRepository.findBySessionAndCredentials(
credentials.getInternal().getId(),
rawCredentials);
} catch (RepositoryOperationFailureException e) {
throw new ContentValidationFailureException(e.getMessage());
}

try {
return contentRepository
.findByProviderAndSecret(rawProvider.getId(), secret.getId())
.stream()
.anyMatch(element -> Objects.equals(element.getLocation(), location));
} catch (RepositoryOperationFailureException e) {
throw new ContentValidationFailureException(e);
}
}

/**
* Retrieves all the data from content repository in a form of content applications.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public ContentRetrievalResult retrieveContent(ContentRetrievalApplication conten
throw new ClusterContentRetrievalFailureException(e.getMessage());
}

List<RepositoryContentLocationUnitDto> repositoryContentLocations;

try {
repositoryContentLocations =
repositoryFacade.retrieveLocations(contentRetrievalApplication);
} catch (ContentLocationsRetrievalFailureException e) {
StateService.getTopologyStateGuard().unlock();

throw new ClusterContentRetrievalFailureException(e.getMessage());
}

ContentRetrievalResult result = new ContentRetrievalResult();

for (String locationUnit : locationUnits) {
Expand All @@ -89,6 +100,7 @@ public ContentRetrievalResult retrieveContent(ContentRetrievalApplication conten
throw new ClusterContentRetrievalFailureException(e.getMessage());
}


List<String> additionalContentUnits;

try {
Expand All @@ -100,15 +112,10 @@ public ContentRetrievalResult retrieveContent(ContentRetrievalApplication conten
throw new ClusterContentRetrievalFailureException(e.getMessage());
}

Boolean active = false;

try {
active = repositoryFacade.isContentLocationValid(
locationUnit,
contentRetrievalApplication.getProvider(),
contentRetrievalApplication.getCredentials());
} catch (ContentValidationFailureException ignored) {
}
Boolean active =
repositoryContentLocations
.stream()
.anyMatch(element -> Objects.equals(element.getLocation(), locationUnit));

result.addLocationsItem(
ContentRetrievalUnit.of(
Expand All @@ -118,6 +125,23 @@ public ContentRetrievalResult retrieveContent(ContentRetrievalApplication conten
ContentRetrievalUnitAdditional.of(additionalContentUnits)));
}

for (RepositoryContentLocationUnitDto repositoryContentLocation : repositoryContentLocations) {
if (!result
.getLocations()
.stream()
.anyMatch(element ->
Objects.equals(
element.getName(), repositoryContentLocation.getLocation()))) {
result.addLocationsItem(
ContentRetrievalUnit.of(
repositoryContentLocation.getLocation(),
true,
ContentRetrievalUnitRaw.of(new ArrayList<>()),
ContentRetrievalUnitAdditional.of(new ArrayList<>())));

}
}

StateService.getTopologyStateGuard().unlock();

return result;
Expand Down
5 changes: 5 additions & 0 deletions api-server/src/main/openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ components:
ContentRetrievalUnit:
required:
- name
- active
- raw
- additional
properties:
Expand All @@ -258,12 +259,16 @@ components:
additional:
$ref: "#/components/schemas/ContentRetrievalUnitAdditional"
ContentRetrievalUnitRaw:
required:
- versions
properties:
versions:
type: array
items:
type: string
ContentRetrievalUnitAdditional:
required:
- versions
properties:
versions:
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.repoachiever.model.ContentDownload;
import com.repoachiever.model.ContentWithdrawal;
import com.repoachiever.service.client.common.IClient;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.reactive.function.client.WebClientResponseException;
Expand All @@ -23,6 +25,10 @@ public class DownloadContentClientService implements IClient<byte[], ContentDown

public DownloadContentClientService(String host) {
ApiClient apiClient = new ApiClient(WebClient.builder()
.exchangeStrategies(ExchangeStrategies.builder()
.codecs(codecs -> codecs.defaultCodecs()
.maxInMemorySize(-1))
.build())
.clientConnector(new ReactorClientHttpConnector(
HttpClient.create().followRedirect(true)))
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.repoachiever.service.visualization.state.VisualizationState;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.stereotype.Service;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void performServe() throws RemoteException {
*/
@Override
public void performRetrievalReset() throws RemoteException {
StateService.resetContentUpdatesHeadCounter();
// StateService.resetContentUpdatesHeadCounter();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.stereotype.Service;

import java.io.InputStream;
Expand Down Expand Up @@ -72,16 +74,18 @@ private IApiServerCommunicationService retrieveAllocation() throws ApiServerOper
* @param name given content name.
* @throws ApiServerOperationFailureException if RepoAchiever API Server operation fails.
*/
public void performRawContentUpload(String location, String name, InputStream content) throws ApiServerOperationFailureException {
public void performRawContentUpload(String location, String name, DataBuffer content) throws ApiServerOperationFailureException {
IApiServerCommunicationService allocation = retrieveAllocation();

RemoteInputStream contentWrapped;

try {
contentWrapped = new SimpleRemoteInputStream(content)
contentWrapped = new SimpleRemoteInputStream(content.asInputStream())
.export();
} catch (RemoteException e) {
throw new RuntimeException(e);
DataBufferUtils.release(content);

throw new ApiServerOperationFailureException(e.getMessage());
}

try {
Expand All @@ -91,8 +95,12 @@ public void performRawContentUpload(String location, String name, InputStream co
name,
contentWrapped);
} catch (RemoteException e) {
DataBufferUtils.release(content);

throw new ApiServerOperationFailureException(e.getMessage());
}

DataBufferUtils.release(content);
}

/**
Expand Down
Loading

0 comments on commit ea2ecf5

Please sign in to comment.