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

[CEP-389] Fix cached JWT #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>co.macrometa</groupId>
<artifactId>c84j</artifactId>
<version>1.1.25</version>
<version>1.1.25.3-SNAPSHOT</version>
<inceptionYear>2019</inceptionYear>
<packaging>jar</packaging>

Expand Down Expand Up @@ -334,7 +334,7 @@
<url>https://github.com/Macrometacorp/C84j.git</url>
<connection>scm:git:git@github.com:Macrometacorp/C84j.git</connection>
<developerConnection>scm:git:git@github.com:Macrometacorp/C84j.git</developerConnection>
<tag>c84j-1.1.25</tag>
<tag>c84j-1.1.25.1</tag>
</scm>

<organization>
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/c8db/C8Compute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (c) 2022 Macrometa Corp All rights reserved.
*/
package com.c8db;

import com.c8db.entity.FxEntity;
import com.c8db.entity.FxMetadataEntity;
import com.c8db.model.FxReadOptions;

import java.util.Collection;
import java.util.Map;

public interface C8Compute {

/**
* Fetches a list of all functions.
*
* @return
* @throws C8DBException
*/
Collection<FxEntity> getFunctions() throws C8DBException;

/**
* Fetches a list of all functions.
*
* @param options - filter by FxReadOptions instance
* @return
* @throws C8DBException
*/
Collection<FxEntity> getFunctions(final FxReadOptions options) throws C8DBException;

/**
* Get information about function worker.
*
* @return - result as FxEntity object
* @throws C8DBException
*/
FxEntity getInfo(final String name) throws C8DBException;

/**
* Fetch information about a edge worker.
*
* @return - result as FxMetadataEntity object
* @throws C8DBException
*/
FxMetadataEntity getMetadata() throws C8DBException;

/**
* Execute a function worker.
*
* @param name - name of function
* @param arguments - set parameters with arguments as a map
* @return - result of execution of a function.
* @throws C8DBException
*/
Collection<Map<String, Object>> executeFunction(String name, Map<String, Object> arguments) throws C8DBException;
}
47 changes: 47 additions & 0 deletions src/main/java/com/c8db/C8ComputeImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) 2022 Macrometa Corp All rights reserved.
*/
package com.c8db;

import com.c8db.entity.FxEntity;
import com.c8db.entity.FxMetadataEntity;
import com.c8db.internal.C8DBImpl;
import com.c8db.internal.C8DatabaseImpl;
import com.c8db.internal.C8ExecutorSync;
import com.c8db.internal.InternalC8Compute;
import com.c8db.model.FxReadOptions;

import java.util.Collection;
import java.util.Map;

public class C8ComputeImpl extends InternalC8Compute<C8DBImpl, C8DatabaseImpl, C8ExecutorSync> implements C8Compute {

public C8ComputeImpl(C8DatabaseImpl db) {
super(db);
}

@Override
public Collection<FxEntity> getFunctions() throws C8DBException {
return getFunctions(null);
}

@Override
public Collection<FxEntity> getFunctions(final FxReadOptions options) throws C8DBException {
return executor.execute(getFunctionsRequest(options), getFunctionsResponseDeserializer(), null, Service.C8FUNCTION);
}

@Override
public FxEntity getInfo(String name) throws C8DBException {
return executor.execute(getInfoRequest(name), getInfoResponseDeserializer(), null, Service.C8FUNCTION);
}

@Override
public FxMetadataEntity getMetadata() throws C8DBException {
return executor.execute(getMetadataRequest(), getMetadataResponseDeserializer(), null, Service.C8FUNCTION);
}

@Override
public Collection<Map<String, Object>> executeFunction(String name, Map<String, Object> arguments) throws C8DBException {
return executor.execute(executeFunctionRequest(name, arguments), executeFunctionResponseDeserializer(), null, Service.C8FUNCTION);
}
}
17 changes: 15 additions & 2 deletions src/main/java/com/c8db/C8DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.c8db.entity.DataCenterEntity;
import com.c8db.entity.DcInfoEntity;
import com.c8db.entity.GeoFabricEntity;
import com.c8db.entity.GeoFabricPermissions;
import com.c8db.entity.LoadBalancingStrategy;
import com.c8db.entity.LogEntity;
import com.c8db.entity.LogLevelEntity;
Expand Down Expand Up @@ -149,6 +148,17 @@ public Builder timeout(final Integer timeout) {
return this;
}

/**
* Sets the response size in bytes.
*
* @param responseSizeLimit size in bytes
* @return {@link C8DB.Builder}
*/
public Builder responseSizeLimit(final Integer responseSizeLimit) {
setResponseSizeLimit(responseSizeLimit);
return this;
}

/**
* Sets the username to use for authentication.
*
Expand Down Expand Up @@ -611,6 +621,9 @@ public synchronized C8DB build() {
if (hosts.get(Service.C8STREAMS).isEmpty()) {
hosts.get(Service.C8STREAMS).addAll(hosts.get(Service.C8DB));
}
if (hosts.get(Service.C8FUNCTION).isEmpty()) {
hosts.get(Service.C8FUNCTION).addAll(hosts.get(Service.C8DB));
}

final VPack vpacker = vpackBuilder.serializeNullValues(false).build();
final VPack vpackerNull = vpackBuilder.serializeNullValues(true).build();
Expand All @@ -630,7 +643,7 @@ public synchronized C8DB build() {

final ConnectionFactory connectionFactory = (protocol == null || Protocol.VST == protocol)
? new VstConnectionFactorySync(host, timeout, connectionTtl, useSsl, sslContext)
: new HttpConnectionFactory(timeout, user, password, email, jwtAuth, useSsl, sslContext, custom, protocol,
: new HttpConnectionFactory(timeout, responseSizeLimit, user, password, email, jwtAuth, useSsl, sslContext, custom, protocol,
connectionTtl, httpCookieSpec, jwtToken, apiKey, hosts.get(Service.C8DB).get(0));

final Map<Service, Collection<Host>> hostsMatrix = createHostMatrix(max, connectionFactory);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/c8db/C8Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,4 +750,10 @@ <V, E> TraversalEntity<V, E> executeTraversal(Class<V> vertexClass, Class<E> edg
*/
C8Dynamo dynamo(final String tableName);

/**
* Returns a {@code C8Compute} instance.
* @return C8Compute handler
*/
C8Compute compute();

}
3 changes: 2 additions & 1 deletion src/main/java/com/c8db/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public enum Service {

C8DB,
C8STREAMS
C8STREAMS,
C8FUNCTION

}
86 changes: 86 additions & 0 deletions src/main/java/com/c8db/entity/FxEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright (c) 2022 Macrometa Corp All rights reserved.
*/
package com.c8db.entity;

import com.arangodb.velocypack.annotations.SerializedName;

/**
* Class describes function worker
*/
public class FxEntity implements Entity {

@SerializedName("_id")
private String id;
@SerializedName("_key")
private String key;
@SerializedName("_rev")
private String rev;
private String activationStatus;
private long createdAt;
private long edgeWorkerId;
private String environment;
private String fabric;
private long lastModified;
private String name;
private String queryWorkerName;
private String queue;
private FxType type;
private String url;

public String getId() {
return id;
}

public String getKey() {
return key;
}

public String getRev() {
return rev;
}

public String getActivationStatus() {
return activationStatus;
}

public long getCreatedAt() {
return createdAt;
}

public long getEdgeWorkerId() {
return edgeWorkerId;
}

public String getEnvironment() {
return environment;
}

public String getFabric() {
return fabric;
}

public long getLastModified() {
return lastModified;
}

public String getName() {
return name;
}

public String getQueryWorkerName() {
return queryWorkerName;
}

public String getQueue() {
return queue;
}

public FxType getType() {
return type;
}

public String getUrl() {
return url;
}
}
68 changes: 68 additions & 0 deletions src/main/java/com/c8db/entity/FxMetadataEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) 2022 Macrometa Corp All rights reserved.
*/
package com.c8db.entity;

public class FxMetadataEntity implements Entity {

private String accessToken;
private String baseUri;
private String clientSecret;
private String clientToken;
private String contractId;
private String gdnApiKey;
private String gdnApiKeyName;
private String groupId;
private String hostName;
private String propertyId;
private String resourceTierId;
private FxType type;

public String getAccessToken() {
return accessToken;
}

public String getBaseUri() {
return baseUri;
}

public String getClientSecret() {
return clientSecret;
}

public String getClientToken() {
return clientToken;
}

public String getContractId() {
return contractId;
}

public String getGdnApiKey() {
return gdnApiKey;
}

public String getGdnApiKeyName() {
return gdnApiKeyName;
}

public String getGroupId() {
return groupId;
}

public String getHostName() {
return hostName;
}

public String getPropertyId() {
return propertyId;
}

public String getResourceTierId() {
return resourceTierId;
}

public FxType getType() {
return type;
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/c8db/entity/FxType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2022 Macrometa Corp All rights reserved.
*/
package com.c8db.entity;

/**
* Class describes type of function worker.
*/
public enum FxType {

ALL,
AKAMAI,
MACROMETA

}
7 changes: 7 additions & 0 deletions src/main/java/com/c8db/internal/C8DatabaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.c8db.C8Alerts;
import com.c8db.C8ApiKeys;
import com.c8db.C8Collection;
import com.c8db.C8Compute;
import com.c8db.C8ComputeImpl;
import com.c8db.C8Cursor;
import com.c8db.C8Database;
import com.c8db.C8Dynamo;
Expand Down Expand Up @@ -494,4 +496,9 @@ public C8KeyValue kv(final String name) {
public C8Dynamo dynamo(String tableName) {
return new C8DynamoImpl(this, tableName);
}

@Override
public C8Compute compute() {
return new C8ComputeImpl(this);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/c8db/internal/C8Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private C8Defaults() {
public static final String DEFAULT_DC_LIST = "tonchev-europe-west4,tonchev-europe-west1";
public static final String DEFAULT_TENANT = "demo";
public static final Integer DEFAULT_TIMEOUT = 0;
public static final Integer DEFAULT_RESPONSE_SIZE_LIMIT = 1024 * 1024;
public static final String DEFAULT_USER = "root";
public static final Boolean DEFAULT_USE_SSL = true;
public static final Boolean DEFAULT_JWT_AUTH = true;
Expand Down
Loading