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

Feature: implement GUI interface #21

Merged
merged 9 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading