Skip to content

Commit

Permalink
Merge branch 'github/ci' of github.com:mycloudnexus/kraken into githu…
Browse files Browse the repository at this point in the history
…b/ci
  • Loading branch information
DaveXiong committed Nov 6, 2024
2 parents fb56735 + 04410c6 commit bf53dcd
Show file tree
Hide file tree
Showing 41 changed files with 1,823 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "${entity.id}",
"buyerRequestedQuoteLevel": "${mefRequestBody.buyerRequestedQuoteLevel}",
"relatedContactInformation": "${T(com.consoleconnect.kraken.operator.gateway.func.SpelFunc).appendSellerInformation('sellerContactInformation',env.seller.name,env.seller.emailAddress,env.seller.number,mefRequestBody.relatedContactInformation)}",
"relatedContactInformation": "${T(com.consoleconnect.kraken.operator.gateway.func.SpelFunc).appendSellerInformation('sellerContactInformation',env.seller.name,env.seller.emailAddress,env.seller.number,mefRequestBody[relatedContactInformation]?:'')}",
"quoteItem": [
{
"requestedQuoteItemTerm": "${mefRequestBody.quoteItem[0].requestedQuoteItemTerm}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
{
"id": "${entity.id}",
"buyerRequestedQuoteLevel": "${mefRequestBody.buyerRequestedQuoteLevel}",
"relatedContactInformation": "${T(com.consoleconnect.kraken.operator.gateway.func.SpelFunc).appendSellerInformation('sellerContactInformation', env.seller.name, env.seller.emailAddress, env.seller.number, mefRequestBody.relatedContactInformation)}",
"relatedContactInformation": "${T(com.consoleconnect.kraken.operator.gateway.func.SpelFunc).appendSellerInformation('sellerContactInformation', env.seller.name, env.seller.emailAddress, env.seller.number, mefRequestBody[relatedContactInformation]?:'')}",
"quoteItem": [{
"requestedQuoteItemTerm": "${mefRequestBody.quoteItem[0].requestedQuoteItemTerm}",
"product": "${mefRequestBody.quoteItem[0].product}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
{
"id": "${entity.id}",
"buyerRequestedQuoteLevel": "${mefRequestBody.buyerRequestedQuoteLevel}",
"relatedContactInformation": "${T(com.consoleconnect.kraken.operator.gateway.func.SpelFunc).appendSellerInformation('sellerContactInformation', env.seller.name, env.seller.emailAddress, env.seller.number, mefRequestBody.relatedContactInformation)}",
"relatedContactInformation": "${T(com.consoleconnect.kraken.operator.gateway.func.SpelFunc).appendSellerInformation('sellerContactInformation', env.seller.name, env.seller.emailAddress, env.seller.number, mefRequestBody[relatedContactInformation]?:'')}",
"quoteItem": [
{
"requestedQuoteItemTerm": "${mefRequestBody.quoteItem[0].requestedQuoteItemTerm}",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.consoleconnect.kraken.operator.controller.api;

import static com.consoleconnect.kraken.operator.core.model.HttpResponse.ok;

import com.consoleconnect.kraken.operator.controller.dto.statistics.ApiRequestActivityStatistics;
import com.consoleconnect.kraken.operator.controller.dto.statistics.ErrorApiRequestStatistics;
import com.consoleconnect.kraken.operator.controller.dto.statistics.MostPopularEndpointStatistics;
import com.consoleconnect.kraken.operator.controller.service.statistics.ApiActivityStatisticsService;
import com.consoleconnect.kraken.operator.core.model.HttpResponse;
import com.consoleconnect.kraken.operator.core.request.ApiStatisticsSearchRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.ZonedDateTime;
import lombok.AllArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@AllArgsConstructor
@RestController()
@RequestMapping(
value = "/products/{productId}/envs/{envId}/statistics",
produces = MediaType.APPLICATION_JSON_VALUE)
@Tag(name = "API Activities Statistics", description = "API Activities Statistics")
public class EnvAPIActivityStatisticsController {

private final ApiActivityStatisticsService apiActivityStatisticsService;

@Operation(summary = "Load api activity request statistics")
@GetMapping("/api-activity-requests")
public HttpResponse<ApiRequestActivityStatistics> getRequestStatistics(
@PathVariable("productId") String productId,
@PathVariable("envId") String envId,
@RequestParam(value = "requestStartTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
ZonedDateTime requestStartTime,
@RequestParam(value = "requestEndTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
ZonedDateTime requestEndTime,
@RequestParam(value = "buyerId", required = false) String buyerId) {

return ok(
apiActivityStatisticsService.loadRequestStatistics(
ApiStatisticsSearchRequest.builder()
.env(envId)
.buyerId(buyerId)
.queryStart(requestStartTime)
.queryEnd(requestEndTime)
.build()));
}

@Operation(summary = "Load error request statistics")
@GetMapping("/error-requests")
public HttpResponse<ErrorApiRequestStatistics> getErrorStatistics(
@PathVariable("productId") String productId,
@PathVariable("envId") String envId,
@RequestParam(value = "requestStartTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
ZonedDateTime requestStartTime,
@RequestParam(value = "requestEndTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
ZonedDateTime requestEndTime,
@RequestParam(value = "buyerId", required = false) String buyerId) {

return ok(
apiActivityStatisticsService.loadErrorsStatistics(
ApiStatisticsSearchRequest.builder()
.env(envId)
.buyerId(buyerId)
.queryStart(requestStartTime)
.queryEnd(requestEndTime)
.build()));
}

@Operation(summary = "Load most popular endpoint statistics")
@GetMapping("/most-popular-endpoint")
public HttpResponse<MostPopularEndpointStatistics> getMostPopularEndpointStatistics(
@PathVariable("productId") String productId,
@PathVariable("envId") String envId,
@RequestParam(value = "requestStartTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
ZonedDateTime requestStartTime,
@RequestParam(value = "requestEndTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
ZonedDateTime requestEndTime,
@RequestParam(value = "buyerId", required = false) String buyerId) {

return ok(
apiActivityStatisticsService.loadMostPopularEndpointStatistics(
ApiStatisticsSearchRequest.builder()
.env(envId)
.buyerId(buyerId)
.queryStart(requestStartTime)
.queryEnd(requestEndTime)
.build()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.consoleconnect.kraken.operator.controller.api;

import com.consoleconnect.kraken.operator.controller.dto.start.StartGuideInfoDto;
import com.consoleconnect.kraken.operator.controller.service.start.StartGuideService;
import com.consoleconnect.kraken.operator.core.model.HttpResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = StartGuideController.URL, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
@Tag(name = "Start Guide APIs", description = "Portal APIs")
public class StartGuideController {

public static final String URL = "/start/guide";
private final StartGuideService service;

@Operation(summary = "Get start guide info")
@GetMapping("/{productId}")
public HttpResponse<StartGuideInfoDto> getStartGuideInfo(
@PathVariable("productId") String productId, @RequestParam(value = "kind") String kind) {
return HttpResponse.ok(service.getStartGuideInfo(productId, kind));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public HttpResponse<Paging<TemplateUpgradeReleaseVO>> listTemplateChangeLog(

@Operation(summary = "stage environment upgrade check")
@GetMapping("/stage-upgrade-check")
public HttpResponse<List<String>> checkStageUpgradeCondition(
public HttpResponse<TemplateUpgradeCheckDTO> checkStageUpgradeCondition(
@PathVariable("productId") String productId,
@RequestParam(value = "templateUpgradeId", required = false) String templateUpgradeId,
@RequestParam String envId) {
Expand All @@ -147,7 +147,7 @@ public HttpResponse<List<String>> checkStageUpgradeCondition(

@Operation(summary = "product environment upgrade check")
@GetMapping("/production-upgrade-check")
public HttpResponse<List<String>> checkProductionUpgradeCondition(
public HttpResponse<TemplateUpgradeCheckDTO> checkProductionUpgradeCondition(
@PathVariable("productId") String productId,
@RequestParam(value = "templateUpgradeId", required = false) String templateUpgradeId,
@RequestParam String envId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.consoleconnect.kraken.operator.controller.dto;

import java.util.ArrayList;
import java.util.List;
import lombok.Data;

@Data
public class TemplateUpgradeCheckDTO {
Boolean compatible;
Boolean mapperCompleted;
Boolean newerTemplate;
List<String> errorMessages = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.consoleconnect.kraken.operator.controller.dto.start;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiMappingInfoDto {

private Boolean atLeastOneMappingCompleted;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.consoleconnect.kraken.operator.controller.dto.start;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class DeploymentInfoDto {
private Boolean atLeastOneApiDeployedToStage;
private Boolean atLeastOneBuyerRegistered;
private Boolean atLeastOneApiDeployedToProduction;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.consoleconnect.kraken.operator.controller.dto.start;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SellerApiServerRegistrationInfoDto {

private Boolean atLeastOneSellerApiRegistered;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.consoleconnect.kraken.operator.controller.dto.start;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class StartGuideInfoDto {
private SellerApiServerRegistrationInfoDto sellerApiServerRegistrationInfo;
private ApiMappingInfoDto apiMappingInfo;
private DeploymentInfoDto deploymentInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.consoleconnect.kraken.operator.controller.dto.statistics;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiRequestActivityStatistics {
private List<RequestStatistics> requestStatistics;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.consoleconnect.kraken.operator.controller.dto.statistics;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class EndpointUsage {
private String method;
private String endpoint;
private Long usage;
private double popularity;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.consoleconnect.kraken.operator.controller.dto.statistics;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ErrorApiRequestStatistics {
private List<ErrorBreakdown> errorBreakdowns;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.consoleconnect.kraken.operator.controller.dto.statistics;

import java.time.LocalDate;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ErrorBreakdown {
private LocalDate date;
private Map<Integer, Long> errors;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.consoleconnect.kraken.operator.controller.dto.statistics;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MostPopularEndpointStatistics {
private List<EndpointUsage> endpointUsages;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.consoleconnect.kraken.operator.controller.dto.statistics;

import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class RequestStatistics {
private LocalDate date;
private Long success;
private Long error;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1078,11 +1078,11 @@ private void checkIsLatestUpgrade(String currentTemplateUpgradeId) {
}
}

public List<String> stageCheck(String templateUpgradeId, String stageEnvId) {
List<String> resultList = new ArrayList<>();
public TemplateUpgradeCheckDTO stageCheck(String templateUpgradeId, String stageEnvId) {
TemplateUpgradeCheckDTO templateUpgradeCheckDTO = new TemplateUpgradeCheckDTO();
Environment environment = environmentService.findOne(stageEnvId);
if (!environment.getName().equalsIgnoreCase(EnvNameEnum.STAGE.name())) {
resultList.add("error environment: not stage environment");
throw KrakenException.badRequest("error environment: not stage environment");
}
List<ApiMapperDeploymentDTO> stageRunningMappers =
productDeploymentService.listRunningApiMapperDeploymentV3(stageEnvId);
Expand All @@ -1094,34 +1094,32 @@ public List<String> stageCheck(String templateUpgradeId, String stageEnvId) {
.filter(t -> runningMapperKeys.contains(t.getTargetMapperKey()))
.anyMatch(
t -> t.getMappingStatus().equalsIgnoreCase(MappingStatusEnum.INCOMPLETE.getDesc()));
if (existedInCompleted) {
resultList.add(
"Please adjust and complete the incomplete mapping use cases that will be upgraded to data plane.");
}
templateUpgradeCheckDTO.setMapperCompleted(!existedInCompleted);
boolean newTemplate = true;
try {
checkIsLatestUpgrade(templateUpgradeId);
} catch (Exception e) {
resultList.add(e.getMessage());
newTemplate = false;
} finally {
templateUpgradeCheckDTO.setNewerTemplate(newTemplate);
}
return resultList;
return templateUpgradeCheckDTO;
}

public List<String> productionCheck(String templateUpgradeId, String productionEnvId) {
List<String> resultList = new ArrayList<>();
public TemplateUpgradeCheckDTO productionCheck(String templateUpgradeId, String productionEnvId) {
TemplateUpgradeCheckDTO templateUpgradeCheckDTO = new TemplateUpgradeCheckDTO();
Environment environment = environmentService.findOne(productionEnvId);
if (!environment.getName().equalsIgnoreCase(EnvNameEnum.PRODUCTION.name())) {
resultList.add("error environment: not production environment");
}
if (!checkStageCompatibility(templateUpgradeId)) {
resultList.add(
"Kraken version running in stage data plane is not compatible with this mapping template. Please upgrade kraken in stage data plane and Start verification");
throw KrakenException.badRequest("error environment: not production environment");
}
templateUpgradeCheckDTO.setCompatible(checkStageCompatibility(templateUpgradeId));
boolean newTemplate = true;
try {
checkIsLatestUpgrade(templateUpgradeId);
} catch (Exception e) {
resultList.add(e.getMessage());
newTemplate = false;
} finally {
templateUpgradeCheckDTO.setNewerTemplate(newTemplate);
}
return resultList;
return templateUpgradeCheckDTO;
}

public boolean checkStageCompatibility(String templateUpgradeId) {
Expand Down
Loading

0 comments on commit bf53dcd

Please sign in to comment.