Skip to content

Commit

Permalink
Merge pull request #107 from dterefe/main
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
dterefe authored Oct 27, 2024
2 parents 96944cb + 93d76a8 commit 8dc2f2a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.InvalidParameterException;
import java.time.Instant;
import java.util.*;
Expand Down Expand Up @@ -2483,6 +2485,11 @@ public static void main(String[] args) throws Exception {
// Merge -> Vereint das in _InitialView


// Engine 1 -> track 1 schreibt
// Engine 2 -> track 2 schreibt
// Merge -> Vereint das in _InitialView


// SpaCy Lemma, POS, NER besser in NER, Precision
// StanfordNlpNER NER

Expand All @@ -2503,7 +2510,7 @@ public static void main(String[] args) throws Exception {
.withScale(1)
, DUUISwarmDriver.class);*/
composer.add(new DUUIRemoteDriver.Component("http://127.0.0.1:9715")
.withScale(1).withWebsocket(true).build());
.withScale(1).withWebsocket(true).build());
// composer.add(new SocketIO("http://127.0.0.1:9715"));

// ByteArrayInputStream stream;
Expand Down Expand Up @@ -2554,7 +2561,7 @@ public static void main(String[] args) throws Exception {
TextReader.PARAM_LANGUAGE, "en"),"next11");*/
/** @see **/
composer.shutdown();
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,78 @@

public class DUUIGoogleDriveDocumentHandler implements IDUUIDocumentHandler, IDUUIFolderPickerApi {

private static final String APPLICATION_NAME = "DUUI Controller";
private static final String APPLICATION_NAME = "DUUI-Gateway";
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

private static String root = "";
private final Drive service;
public DUUIGoogleDriveDocumentHandler(Credential credential) throws GeneralSecurityException, IOException {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();

if (!folderExists(service)) {
File appsFolder = new File()
.setName("Apps")
.setMimeType("application/vnd.google-apps.folder");

File createdAppsFolder = service.files().create(appsFolder).setFields("id").execute();

File duuiFolder = new File()
.setName("Docker Unified UIMA Interface")
.setMimeType("application/vnd.google-apps.folder")
.setParents(Collections.singletonList(createdAppsFolder.getId()));

File createdDuuiFolder = service.files().create(duuiFolder).setFields("id").execute();

root = createdDuuiFolder.getId();
}

}

public static boolean folderExists(Drive service) throws IOException, IllegalStateException {
String folderName = "Docker Unified UIMA Interface";
String parentFolderName = "Apps";

// Search for the Docker Unified UIMA Interface folder
String query = "mimeType='application/vnd.google-apps.folder' and name='" + folderName + "'";
FileList result = service.files().list()
.setQ(query)
.setFields("files(id, name, parents)")
.execute();

List<File> files = result.getFiles();

if (files.isEmpty()) {
return false;
}

if (files.size() > 1) {
throw new IllegalStateException("Multiple folders named '" + folderName + "' found. Please delete all (including the ones contained in the trash) but one.");
}

File duuiFolder = files.get(0);

if (duuiFolder.getParents() == null || duuiFolder.getParents().isEmpty()) {
throw new IllegalStateException("The folder '" + folderName + "' has no parent. This is not allowed.");
}

if (duuiFolder.getParents().size() > 1) {
throw new IllegalStateException("The folder '" + folderName + "' has multiple parents. This is not allowed.");
}

String parentId = duuiFolder.getParents().get(0);
File parentFolder = service.files().get(parentId)
.setFields("id, name")
.execute();

if (!parentFolder.getName().equalsIgnoreCase(parentFolderName)) {
throw new IllegalStateException("The parent folder is not '" + parentFolderName + "'. Please check the folder structure.");
}

root = duuiFolder.getId();

return true;
}

public static void main(String... args) throws IOException, GeneralSecurityException {
Expand All @@ -40,10 +103,12 @@ public static void main(String... args) throws IOException, GeneralSecurityExcep
// .setAccessToken(accessToken);
//
// DUUIGoogleDriveDocumentHandler handler = new DUUIGoogleDriveDocumentHandler(credential);
//

// System.out.println("Apps/Docker Unified UIMA Interface: " + root);
// System.out.println(handler.getFolderStructure().toJson());
// handler.listDocuments("1JpyqWuWCXLK4Y5DI6mmKyddY1h-BWww8", "txt").stream()
// .map(DUUIDocument::getPath)
// handler.listDocuments(root, "xmi").stream()
// .map(DUUIDocument::getName)
// .forEach(System.out::println);
// .map(d -> {
// try {
// return handler.readDocument(d);
Expand Down Expand Up @@ -214,7 +279,7 @@ public List<DUUIDocument> listDocuments_(String searchPath, String fileExtension
@Override
public DUUIFolder getFolderStructure() {

DUUIFolder root = new DUUIFolder("root", "Files");
DUUIFolder root = new DUUIFolder(this.root, "Files");

return getFolderStructure(root);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.logging.Logger;

import static java.lang.String.format;
import static org.texttechnologylab.DockerUnifiedUIMAInterface.DUUIComposer.getLocalhost;

/**
* Interface for all drivers
Expand Down Expand Up @@ -310,7 +311,7 @@ public String instantiate(DUUIPipelineComponent component, JCas jc, boolean skip
}
final int iCopy = i;
final String uuidCopy = uuid;
IDUUICommunicationLayer layer = responsiveAfterTime("http://127.0.0.1:" + String.valueOf(port), jc, _container_timeout, _client, (msg) -> {
IDUUICommunicationLayer layer = responsiveAfterTime(getLocalhost() + ":" + String.valueOf(port), jc, _container_timeout, _client, (msg) -> {
System.out.printf("[DockerLocalDriver][%s][Docker Replication %d/%d] %s\n", uuidCopy, iCopy + 1, comp.getScale(), msg);
}, _luaContext, skipVerification);
System.out.printf("[DockerLocalDriver][%s][Docker Replication %d/%d] Container for image %s is online (URL http://127.0.0.1:%d) and seems to understand DUUI V1 format!\n", uuid, i + 1, comp.getScale(), comp.getImageName(), port);
Expand Down Expand Up @@ -467,11 +468,11 @@ int getContainerPort() {
}

public String generateURL() {
return format("http://127.0.0.1:%d", _port);
return format(getLocalhost() + ":%d", _port);
}

String getContainerUrl() {
return format("http://127.0.0.1:%d", _port);
return format(getLocalhost() + ":%d", _port);
}

public IDUUIConnectionHandler getHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public DUUIPipelineComponent withTargetView(String viewName) {
}

public DUUIPipelineComponent withTimeout(long lLong) {
_options.put(timeout, String.valueOf(lLong));
_parameters.put(timeout, String.valueOf(lLong));
return this;
}

Expand Down Expand Up @@ -665,6 +665,6 @@ public DUUISegmentationStrategy getSegmentationStrategy() {
}

public long getTimeout() {
return Long.valueOf(_options.getOrDefault(timeout, "60"));
return Long.valueOf(_parameters.getOrDefault(timeout, "60"));
}
}

0 comments on commit 8dc2f2a

Please sign in to comment.