Skip to content

Commit

Permalink
Merge branch 'release/0.18.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Holy committed Apr 21, 2021
2 parents 440d184 + 0af7322 commit abce5e0
Show file tree
Hide file tree
Showing 270 changed files with 3,111 additions and 1,596 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GITHUB_BRANCH: ${{ github.ref }}
- name: Publish http-client library to npm
if: ${{ startsWith(github.ref, 'refs/tags/npm-v') }}
run: |
sudo apt-get install -y expect
bazel run //lib/typescript/httpclient:publish-npm release
env:
DEPLOY_NPM_USERNAME: ${{ secrets.DEPLOY_NPM_USERNAME }}
DEPLOY_NPM_PASSWORD: ${{ secrets.DEPLOY_NPM_PASSWORD }}
DEPLOY_NPM_EMAIL: ${{ secrets.DEPLOY_NPM_EMAIL }}
GITHUB_BRANCH: ${{ github.ref }}
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ exports_files(
".prettierrc.json",
".prettierignore",
"yarn.lock",
"VERSION",
],
)

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.17.0
0.18.0
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# Airy Bazel tools
git_repository(
name = "com_github_airyhq_bazel_tools",
commit = "2577f95b79aeef4c70a6aad1805b19ec707dbfa2",
commit = "d18b5a4418a8b69c0a7177f2831f8aa62da038c1",
remote = "https://github.com/airyhq/bazel-tools.git",
shallow_since = "1617890651 +0200",
shallow_since = "1618558833 +0200",
)

load("@com_github_airyhq_bazel_tools//:repositories.bzl", "airy_bazel_tools_dependencies", "airy_jvm_deps")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ResponseEntity<?> connect(@RequestBody @Valid ConnectChannelRequestPayload reque
final String sourceChannelId = requestPayload.getName();
final String sourceIdentifier = "chatplugin";

final String channelId = UUIDv5.fromNamespaceAndName(sourceIdentifier, sourceChannelId).toString();
final String channelId = UUID.randomUUID().toString();

List<Metadata> metadataList = new ArrayList<>();
metadataList.add(newChannelMetadata(channelId, MetadataKeys.ChannelKeys.NAME, requestPayload.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class ClientConfigController {
private final ServiceDiscovery serviceDiscovery;
Expand All @@ -18,7 +16,6 @@ public ClientConfigController(ServiceDiscovery serviceDiscovery) {
public ResponseEntity<ClientConfigResponsePayload> getConfig() {
return ResponseEntity.ok(ClientConfigResponsePayload.builder()
.components(serviceDiscovery.getComponents())
.features(Map.of())
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
@AllArgsConstructor
public class ClientConfigResponsePayload {
private Map<String, Map<String, Object>> components;
private Map<String, String> features;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package co.airy.core.api.config;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class ComponentResponsePayload {
private String name;
private Boolean enabled;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package co.airy.core.api.config;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ComponentsResponsePayload implements Serializable {
private List<String> components;
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
package co.airy.core.api.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;

@Component
public class ServiceDiscovery {
private final String namespace;
private final RestTemplate restTemplate;

private final Map<String, Map<String, Object>> components = new ConcurrentHashMap<>();

private static final List<String> services = List.of(
"sources-chatplugin",
"sources-facebook-connector",
"sources-twilio-connector",
"sources-google-connector"
);
private Map<String, Map<String, Object>> components = new ConcurrentHashMap<>();

public ServiceDiscovery(@Value("${kubernetes.namespace}") String namespace, RestTemplate restTemplate) {
this.namespace = namespace;
Expand All @@ -36,13 +30,12 @@ public Map<String, Map<String, Object>> getComponents() {

@Scheduled(fixedRate = 1_000)
private void updateComponentsStatus() {
for (String service : services) {
try {
ResponseEntity<Object> response = restTemplate.exchange(String.format("http://%s.%s/actuator/health", service, namespace), HttpMethod.GET, null, Object.class);
components.put(service.replace("-connector", ""), Map.of("enabled", response.getStatusCode().is2xxSuccessful()));
} catch (Exception e) {
components.put(service.replace("-connector", ""), Map.of("enabled",false));
}
final ResponseEntity<ComponentsResponsePayload> response = restTemplate.getForEntity("http://airy-controller.default/components", ComponentsResponsePayload.class);
Map<String, Map<String, Object>> newComponents = new ConcurrentHashMap<>();
for (String component: response.getBody().getComponents()) {
newComponents.put(component, Map.of("enabled", true));
}
components.clear();
components.putAll(newComponents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ kafka.brokers=${KAFKA_BROKERS}
kafka.schema-registry-url=${KAFKA_SCHEMA_REGISTRY_URL}
kafka.cleanup=${KAFKA_CLEANUP:false}
kafka.commit-interval-ms=${KAFKA_COMMIT_INTERVAL_MS}
auth.jwt-secret=${JWT_SECRET}
auth.jwt-secret=${jwtSecret}
kubernetes.namespace=${KUBERNETES_NAMESPACE}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = AirySpringBootApplication.class)
@TestPropertySource(value = "classpath:test.properties", properties = {
"ALLOWED_ORIGINS=origin1,origin2",
"allowedOrigins=origin1,origin2",
})
@AutoConfigureMockMvc
@ExtendWith(SpringExtension.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.client.MockRestServiceServer;
Expand All @@ -31,11 +31,12 @@
import static co.airy.test.Timing.retryOnException;
import static org.hamcrest.CoreMatchers.everyItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.client.ExpectedCount.min;
import static org.springframework.test.web.client.ExpectedCount.once;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand Down Expand Up @@ -91,25 +92,16 @@ void beforeEach() throws Exception {

@Test
public void canReturnConfig() throws Exception {
mockServer.expect(min(1), requestTo(new URI("http://sources-chatplugin.default/actuator/health")))
mockServer.expect(once(), requestTo(new URI("http://airy-controller.default/components")))
.andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK));

mockServer.expect(min(1), requestTo(new URI("http://sources-facebook-connector.default/actuator/health")))
.andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK));

mockServer.expect(min(1), requestTo(new URI("http://sources-twilio-connector.default/actuator/health")))
.andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK));

mockServer.expect(min(1), requestTo(new URI("http://sources-google-connector.default/actuator/health")))
.andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK));
.andRespond(
withSuccess("{\"components\": [\"api-communication\"]}", MediaType.APPLICATION_JSON)
);

retryOnException(() -> webTestHelper.post("/client.config", "{}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.components.*", hasSize(4)))
.andExpect(jsonPath("$.components.*", hasSize(1)))
.andExpect(jsonPath("$.components", hasKey("api-communication")))
.andExpect(jsonPath("$.components.*.enabled", everyItem(is(true)))),
"client.config call failed");
}
Expand Down
2 changes: 1 addition & 1 deletion backend/api/auth/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}

spring.flyway.enabled=true
auth.jwt-secret=${JWT_SECRET}
auth.jwt-secret=${jwtSecret}

mail.host.url=${MAIL_URL}
mail.host.port=${MAIL_PORT}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import co.airy.core.api.communication.payload.ConversationListRequestPayload;
import co.airy.core.api.communication.payload.ConversationListResponsePayload;
import co.airy.core.api.communication.payload.ConversationResponsePayload;
import co.airy.core.api.communication.payload.ConversationSetStateRequestPayload;
import co.airy.core.api.communication.payload.ConversationTagRequestPayload;
import co.airy.core.api.communication.payload.PaginationData;
import co.airy.model.metadata.MetadataKeys;
Expand Down Expand Up @@ -39,6 +40,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import static co.airy.model.metadata.MetadataRepository.newConversationMetadata;
import static co.airy.model.metadata.MetadataRepository.newConversationTag;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -230,4 +232,46 @@ ResponseEntity<?> conversationUntag(@RequestBody @Valid ConversationTagRequestPa

return ResponseEntity.noContent().build();
}

@PostMapping("/conversations.setState")
ResponseEntity<?> conversationSetState(@RequestBody @Valid ConversationSetStateRequestPayload requestPayload) {
final String conversationId = requestPayload.getConversationId().toString();
final String state = requestPayload.getState();
final ReadOnlyKeyValueStore<String, Conversation> store = stores.getConversationsStore();
final Conversation conversation = store.get(conversationId);

if (conversation == null) {
return ResponseEntity.notFound().build();
}

final Metadata metadata = newConversationMetadata(conversationId, MetadataKeys.ConversationKeys.STATE, state);

try {
stores.storeMetadata(metadata);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new RequestErrorResponsePayload(e.getMessage()));
}

return ResponseEntity.noContent().build();
}

@PostMapping("/conversations.removeState")
ResponseEntity<?> conversationRemoveState(@RequestBody @Valid ConversationByIdRequestPayload requestPayload) {
final String conversationId = requestPayload.getConversationId().toString();
final ReadOnlyKeyValueStore<String, Conversation> store = stores.getConversationsStore();
final Conversation conversation = store.get(conversationId);

if (conversation == null) {
return ResponseEntity.notFound().build();
}

try {
final Subject subject = new Subject("conversation", conversationId);
stores.deleteMetadata(subject, MetadataKeys.ConversationKeys.STATE);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new RequestErrorResponsePayload(e.getMessage()));
}

return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package co.airy.core.api.communication.payload;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.util.UUID;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ConversationSetStateRequestPayload {
@NotNull
private UUID conversationId;
@NotNull
private String state;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kafka.schema-registry-url=${KAFKA_SCHEMA_REGISTRY_URL}
kafka.cleanup=${KAFKA_CLEANUP:false}
kafka.commit-interval-ms=${KAFKA_COMMIT_INTERVAL_MS}

auth.jwt-secret=${JWT_SECRET}
auth.jwt-secret=${jwtSecret}
Loading

0 comments on commit abce5e0

Please sign in to comment.