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

feat(sdk): upgrade engine and template #21

Merged
merged 9 commits into from
Oct 30, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.consoleconnect.kraken.operator.config;

import com.consoleconnect.kraken.operator.controller.dto.CreateEnvRequest;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -13,6 +14,6 @@ public class AppMgmtProperty {
@Setter
public static class Product {
private String key;
private List<String> environments;
private List<CreateEnvRequest> environments;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.consoleconnect.kraken.operator.service;

import com.consoleconnect.kraken.operator.config.AppMgmtProperty;
import com.consoleconnect.kraken.operator.controller.dto.CreateEnvRequest;
import com.consoleconnect.kraken.operator.controller.model.Environment;
import com.consoleconnect.kraken.operator.controller.service.EnvironmentService;
import com.consoleconnect.kraken.operator.core.entity.UnifiedAssetEntity;
import com.consoleconnect.kraken.operator.core.event.PlatformSettingCompletedEvent;
import com.consoleconnect.kraken.operator.core.service.UnifiedAssetService;
import com.consoleconnect.kraken.operator.controller.entity.EnvironmentEntity;
import com.consoleconnect.kraken.operator.controller.repo.EnvironmentRepository;
import jakarta.annotation.PostConstruct;
import java.util.List;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@AllArgsConstructor
Expand All @@ -19,48 +17,46 @@
public class EnvironmentInitializer {

private final AppMgmtProperty mgmtProperty;
private final EnvironmentRepository environmentRepository;

private final UnifiedAssetService unifiedAssetService;
private final EnvironmentService environmentService;

@EventListener(PlatformSettingCompletedEvent.class)
@PostConstruct
public void initialize() {
log.info("Initializing environments,{}", mgmtProperty.getProducts());
mgmtProperty
.getProducts()
.forEach(
productEnvironment -> {
log.info("initializing environments for product {}", productEnvironment.getKey());
UnifiedAssetEntity product =
unifiedAssetService.findOneByIdOrKey(productEnvironment.getKey());

List<Environment> existingEnvironments =
environmentService
.search(
product.getKey(),
UnifiedAssetService.getSearchPageRequest(0, Integer.MAX_VALUE))
.getData();
List<EnvironmentEntity> existingEnvironments =
environmentRepository
.findAllByProductId(
productEnvironment.getKey(), PageRequest.of(0, Integer.MAX_VALUE))
.getContent();
productEnvironment.getEnvironments().stream()
.filter(
environmentName ->
environment ->
existingEnvironments.stream()
.noneMatch(
environmentEntity ->
environmentEntity.getName().equals(environmentName)))
environmentEntity.getName().equals(environment.getName())))
.forEach(
environmentName -> {
CreateEnvRequest createEnvRequest = new CreateEnvRequest();
createEnvRequest.setName(environmentName);
environment -> {
log.info(
"creating environment {} for product {}",
environmentName,
product.getKey());
environmentService.create(
product.getId().toString(), createEnvRequest, null);
environment,
productEnvironment.getKey());
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setName(environment.getName());
if (environment.getId() != null) {
environmentEntity.setId(UUID.fromString(environment.getId()));
}
environmentEntity.setProductId(productEnvironment.getKey());
environmentRepository.save(environmentEntity);
log.info(
"created environment {} for product {}",
environmentName,
product.getKey());
environment,
productEnvironment.getKey());
});
});
log.info("initialize environments done");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
server:
port: ${port:8001}

Expand Down Expand Up @@ -73,7 +72,7 @@ springdoc:
swagger-ui:
enabled: true
path: /swagger-ui.html
supported-submit-methods: ["get", "post", "patch", "delete"]
supported-submit-methods: [ "get", "post", "patch", "delete" ]
config-url: /v3/api-docs/swagger-config
urls:
- url: /v3/api-docs
Expand All @@ -89,8 +88,10 @@ app:
products:
- key: mef.sonata
environments:
- stage
- production
- id: 2fd92244-a8d1-43fc-b76d-d87ffb0172f4
name: stage
- id: e1f5d4f6-1cd9-4071-b08c-da72aadc05fe
name: production
mgmt:
enabled: true
apiToken:
Expand Down Expand Up @@ -119,6 +120,9 @@ app:
email: admin
role: ADMIN
password: 182cf072dc112634996cf4abccf2915273ff1a0b53d4436388fe9c55a9531277c6d86a23b7a9addc1c2642a6b62f17cfd18f70c2d98501d520fe4886727b97d1
- name: user_upgrade
email: SYSTEM_UPGRADE
role: INTERNAL_USER
jwt:
issuer: https://kraken.consoleconnect.com/issuer
key-id: kraken
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='kraken_mgmt_event' and column_name='status' and "columns".data_type ='smallint')
THEN
ALTER TABLE kraken_mgmt_event DROP CONSTRAINT kraken_mgmt_event_event_type_check;
ALTER TABLE kraken_mgmt_event DROP CONSTRAINT kraken_mgmt_event_status_check;
ALTER TABLE kraken_mgmt_event ALTER COLUMN status TYPE varchar(255) USING status::varchar(255);
END IF;
END $$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='kraken_mgmt_product_env_client' and column_name='client_ip')
THEN
ALTER TABLE IF EXISTS kraken_mgmt_product_env_client DROP CONSTRAINT IF EXISTS kraken_mgmt_product_env_client_uni_idx;
END IF;
END $$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='kraken_mgmt_product_env_client' and column_name='client_ip')
THEN
ALTER TABLE IF EXISTS kraken_mgmt_product_env_client RENAME COLUMN client_ip TO client_key;
END IF;
END $$;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.consoleconnect.kraken.operator.config.AppMgmtConfig;
import com.consoleconnect.kraken.operator.config.AppMgmtProperty;
import com.consoleconnect.kraken.operator.controller.dto.CreateEnvRequest;
import com.consoleconnect.kraken.operator.test.AbstractIntegrationTest;
import com.consoleconnect.kraken.operator.test.MockIntegrationTest;
import java.util.List;
Expand Down Expand Up @@ -36,7 +37,9 @@ void testPropertyConfig() {
Assertions.assertNotNull(property);
AppMgmtProperty.Product env = new AppMgmtProperty.Product();
env.setKey(UUID.randomUUID().toString());
env.setEnvironments(List.of("dev"));
CreateEnvRequest createEnvRequest = new CreateEnvRequest();
createEnvRequest.setName("dev");
env.setEnvironments(List.of(createEnvRequest));
property.setProducts(List.of(env));
Assertions.assertNotNull(property.getProducts());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import com.consoleconnect.kraken.operator.core.toolkit.PagingHelper;
import java.util.List;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.test.context.TestComponent;
import org.springframework.data.domain.PageRequest;
import org.springframework.util.Assert;

@Slf4j
@TestComponent
public class UserService {
public Paging<User> search(String q, PageRequest pageRequest) {
Expand All @@ -32,4 +34,8 @@ public UserEntity findOneByIdOrEmail(String idOrEmail) {
userEntity.setEmail(idOrEmail);
return userEntity;
}

public void initSystemUpgradeUser() {
log.info("Initializing system upgrade user");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ app:
products:
- key: mef.sonata
environments:
- stage
- production
- id: 2fd92244-a8d1-43fc-b76d-d87ffb0172f4
name: stage
- id: e1f5d4f6-1cd9-4071-b08c-da72aadc05fe
name: production
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
server:
port: ${port:8000}

Expand Down Expand Up @@ -83,3 +82,5 @@ app:
endpoints:
exposure:
include: asset, component, product, ingestion, component-operation
mgmt:
mgmt-server-enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ metadata:
version: 2
spec:
componentPaths:
sampleConfigPaths:
- classpath:/mef-sonata/api-targets-mappers-sample-data/api-target-spec.mock.yaml
- classpath:/mef-sonata/api-targets-mappers-sample-data/api.buyer.mock.yaml
20 changes: 8 additions & 12 deletions kraken-app/kraken-app-hub/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,24 @@ app:
enabled: false
env:
seller:
name: seller-01
number: 123456
name: kraken
number: N/A
role: sellerContact
emailAddress: seller@cc.com
emailAddress: support@kraken.com
filter-headers:
- token
- Authorization
filter-paths:
- /mefApi
cron-job:
push-heartbeat: 0/20 * * * * *
check-release: 0 0/1 * * * *
push-heartbeat: 0/5 * * * * *
check-release: 0/20 * * * * *
security:
resource-server:
enabled: true
jwt:
- issuer: https://kraken.consoleconnect.com/issuer
key-id: kraken
# jwks-uri: http://localhost:8001/.well-known/jwks.json
secret: MjRhMjNhNGYtMWUzMS00ZTY4LTlhYzgtMzY5NDcwYzNjNDE4
bearer-token-header-name: x-kraken-key
unified-asset:
endpoints:
exposure:
include:
secret: ${ACCESS_TOKEN_JWT_SECRET}
bearer-token-header-name: x-sonata-buyer-key
user-id: x-kraken-buyer-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='kraken_mgmt_event' and column_name='status' and "columns".data_type ='smallint')
THEN
ALTER TABLE kraken_mgmt_event DROP CONSTRAINT kraken_mgmt_event_event_type_check;
ALTER TABLE kraken_mgmt_event DROP CONSTRAINT kraken_mgmt_event_status_check;
ALTER TABLE kraken_mgmt_event ALTER COLUMN status TYPE varchar(255) USING status::varchar(255);
END IF;
END $$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='kraken_mgmt_product_env_client' and column_name='client_ip')
THEN
ALTER TABLE IF EXISTS kraken_mgmt_product_env_client DROP CONSTRAINT IF EXISTS kraken_mgmt_product_env_client_uni_idx;
END IF;
END $$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DO $$
BEGIN
IF EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='kraken_mgmt_product_env_client' and column_name='client_ip')
THEN
ALTER TABLE IF EXISTS kraken_mgmt_product_env_client RENAME COLUMN client_ip TO client_key;
END IF;
END $$;
Loading
Loading