Skip to content

Commit

Permalink
Feature: implement GUI interface (#21)
Browse files Browse the repository at this point in the history
* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* feature: implemented external API interface in GUI

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* feature: improved diagnostics metrics

* fix: fixed bugs
  • Loading branch information
YarikRevich authored Jun 1, 2024
1 parent c57bc6b commit 81f836d
Show file tree
Hide file tree
Showing 231 changed files with 5,627 additions and 3,781 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 @@ -3,6 +3,7 @@
import com.repoachiever.model.LocationsUnit;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

Expand All @@ -17,6 +18,12 @@ public class ClusterAllocationDto {
*/
private String name;

/**
* Represents lock state of RepoAchiever Cluster allocation.
*/
@Setter
private Boolean locked;

/**
* Represents workspace unit key used to target RepoAchiever Cluster results.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ public String toString() {
@JsonProperty("content")
public Content content;

/**
* Represents RepoAchiever API Server configuration used for database setup.
*/
@Getter
public static class Database {
@NotNull
@JsonProperty("re-init")
public Boolean reInit;
}

@Valid
@NotNull
@JsonProperty("database")
public Database database;

/**
* Represents RepoAchiever API Server configuration used for diagnostics.
*/
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 @@ -55,13 +55,19 @@ public ApiServerCommunicationResource() throws RemoteException {
@Override
public void performRawContentUpload(
String workspaceUnitKey, String location, String name, RemoteInputStream content) throws RemoteException {
telemetryService.increaseRawContentUploadAmount();

StateService.getCommunicationGuard().lock();

InputStream contentRaw;

try {
contentRaw = RemoteInputStreamClient.wrap(content);
} catch (IOException e) {
StateService.getCommunicationGuard().unlock();

telemetryService.decreaseRawContentUploadAmount();

throw new RuntimeException(e);
}

Expand All @@ -70,10 +76,14 @@ public void performRawContentUpload(
} catch (RawContentCreationFailureException e) {
StateService.getCommunicationGuard().unlock();

telemetryService.decreaseRawContentUploadAmount();

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

StateService.getCommunicationGuard().unlock();

telemetryService.decreaseRawContentUploadAmount();
}

/**
Expand Down Expand Up @@ -105,10 +115,16 @@ public Boolean retrieveRawContentPresent(String workspaceUnitKey, String locatio
@Override
public void performAdditionalContentUpload(
String workspaceUnitKey, String location, String name, String data) throws RemoteException {
telemetryService.increaseAdditionalContentUploadAmount();

StateService.getCommunicationGuard().lock();

Map<String, String> rawData = JsonToAdditionalContentDataConverter.convert(data);
if (Objects.isNull(rawData)) {
StateService.getCommunicationGuard().unlock();

telemetryService.decreaseAdditionalContentUploadAmount();

throw new RemoteException();
}

Expand All @@ -124,10 +140,14 @@ public void performAdditionalContentUpload(
} catch (AdditionalContentCreationFailureException e) {
StateService.getCommunicationGuard().unlock();

telemetryService.decreaseAdditionalContentUploadAmount();

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

StateService.getCommunicationGuard().unlock();

telemetryService.decreaseAdditionalContentUploadAmount();
}

/**
Expand Down Expand Up @@ -161,6 +181,37 @@ public void performLogsTransfer(String name, String message) throws RemoteExcept
logger.info(String.format("Transferred logs(instance: %s): %s", name, message));
}

/**
* @see IApiServerCommunicationService
*/
@Override
public void performDownloadTelemetryIncrease() throws RemoteException {
telemetryService.increaseClusterDownloadAmount();
}

/**
* @see IApiServerCommunicationService
*/
@Override
public void performDownloadTelemetryDecrease() throws RemoteException {
telemetryService.decreaseClusterDownloadAmount();
}

/**
* @see IApiServerCommunicationService
*/
@Override
public void performLockClusterAllocation(String name) throws RemoteException {
}

/**
* @see IApiServerCommunicationService
*/
@Override
public Boolean retrieveClusterAllocationLocked(String name) throws RemoteException {
return false;
}

/**
* @see IApiServerCommunicationService
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
public class ClusterConfigurationHelper {
private final static ScheduledExecutorService scheduledExecutorService =
Executors.newScheduledThreadPool(2);
Executors.newScheduledThreadPool(0, Thread.ofVirtual().factory());

/**
* Composes name for RepoAchiever Cluster using pre-defined prefix and UUID.
Expand All @@ -31,7 +31,7 @@ public static String getName(String prefix) {
public static Boolean waitForStart(Callable<Boolean> callback, Integer frequency, Integer timeout) {
CountDownLatch waiter = new CountDownLatch(1);

ScheduledFuture<?> awaitTask = scheduledExecutorService.scheduleAtFixedRate(() -> {
ScheduledFuture<?> awaitTask = scheduledExecutorService.scheduleWithFixedDelay(() -> {
try {
if (callback.call()) {
waiter.countDown();
Expand Down
Loading

0 comments on commit 81f836d

Please sign in to comment.