diff options
author | 2020-08-31 13:04:35 -0400 | |
---|---|---|
committer | 2020-09-23 16:04:49 -0400 | |
commit | dd74c5ec9c4761de2bec19f9fb53bba36c7c6c2c (patch) | |
tree | 997cd0277ec7e91f5114363aeb39bd591d26e986 /mod2/catalog-service/src/main | |
parent | b4287ad1fab97142df4d5260ec94d41bb782992a (diff) |
adding catalog-service for mod2
Issue-ID: DCAEGEN2-2317
Change-Id: I8a0a85a1db2512744b41efa0a22617747642747d
Signed-off-by: Dhrumin Desai <dd303q@att.com>
Diffstat (limited to 'mod2/catalog-service/src/main')
78 files changed, 4090 insertions, 0 deletions
diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/ModCatalogApplication.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/ModCatalogApplication.java new file mode 100644 index 0000000..d514a69 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/ModCatalogApplication.java @@ -0,0 +1,68 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.ArrayList; + +/** + * The application class + */ +@SpringBootApplication +@EnableSwagger2 +public class ModCatalogApplication { + + public static void main(String[] args) { + SpringApplication.run(ModCatalogApplication.class, args); + } + + @Bean + public Docket swaggerConfiguration(){ + // return a prepared Docket instance + return new Docket(DocumentationType.SWAGGER_2) + .select() + //.paths(PathSelectors.ant("/api/*")) + .apis(RequestHandlerSelectors.basePackage("org.onap.dcaegen2.platform.mod")) + .build() + .apiInfo(apiDetails()); + } + + private ApiInfo apiDetails() { + Contact DEFAULT_CONTACT = new Contact("", "", ""); + return new ApiInfo( + "MOD APIs", + "APIs for MOD", + "1.0.0" + ,"", DEFAULT_CONTACT, "", "", new ArrayList<>() + ); + } + //http://localhost:8080/swagger-ui.html for web page view + //http://localhost:8080/v2/api-docs for json view +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mock/MockDeploymentArtifactGenerator.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mock/MockDeploymentArtifactGenerator.java new file mode 100644 index 0000000..24c31ed --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mock/MockDeploymentArtifactGenerator.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mock; + +import org.onap.dcaegen2.platform.mod.model.specification.Specification; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactGeneratorStrategy; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * Mock implementation for DeploymentArtifactGenerator + */ +@Component +public class MockDeploymentArtifactGenerator implements DeploymentArtifactGeneratorStrategy { + + /** + * null implementation. + * @param activeSpec + * @param release + * @return + */ + @Override + public Map<String, Object> generateForRelease(Specification activeSpec, String release) { + return null; + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mock/MockSpecificationValidationStratergy.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mock/MockSpecificationValidationStratergy.java new file mode 100644 index 0000000..8f9f921 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mock/MockSpecificationValidationStratergy.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mock; + +import org.onap.dcaegen2.platform.mod.model.restapi.SpecificationRequest; +import org.onap.dcaegen2.platform.mod.web.service.specification.SpecificationValidationStratergy; +import org.springframework.stereotype.Component; + +/** + * Mock implementation for SpecificationValidationStrategy + */ +@Component +public class MockSpecificationValidationStratergy implements SpecificationValidationStratergy { + + /** + * Mock implementation + * @param specificationRequest + * @param release + */ + @Override + public void validate(SpecificationRequest specificationRequest, String release) { + //do nothing + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMicroservice.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMicroservice.java new file mode 100644 index 0000000..3e5891f --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMicroservice.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.basemicroservice; + +import org.onap.dcaegen2.platform.mod.model.common.AuditFields; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * A model class which represents Base-Microservice entity + */ +@Data +@NoArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +//TODO: migrate the document to microservices +@Document("base-microservices") +public class BaseMicroservice { + private String id; + + @ApiModelProperty(required = true) + private String name; + + @ApiModelProperty(required = true) + private String tag; + + private String serviceName; + + private BaseMsType type; + + private BaseMsLocation location; + + private String namespace; + + private BaseMsStatus status; + + private AuditFields metadata; + + private List<Map<String, String>> msInstances = new ArrayList<>(); +} + diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsLocation.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsLocation.java new file mode 100644 index 0000000..e8114a5 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsLocation.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.basemicroservice; +/** + * Supported values for Base-Microservice location + */ +public enum BaseMsLocation { + CENTRAL, + EDGE, + UNSPECIFIED +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsStatus.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsStatus.java new file mode 100644 index 0000000..4460e04 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsStatus.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.basemicroservice; + +/** + * Supported statuses for Base-Microservice entity + */ +public enum BaseMsStatus { + ACTIVE, RETIRED +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsType.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsType.java new file mode 100644 index 0000000..1cc81e8 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/basemicroservice/BaseMsType.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.basemicroservice; + +/** + * Supported Types for Base-Microservice + */ +public enum BaseMsType { + TICK, + FM_COLLECTOR, + PM_COLLECTOR, + ANALYTIC, + OTHER +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/common/AuditFields.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/common/AuditFields.java new file mode 100644 index 0000000..d062456 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/common/AuditFields.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Builder; +import lombok.Data; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * A model class for auditfields + */ +@Data +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AuditFields { + + private String createdBy; + private Date createdOn; + private String updatedBy; + private Date updatedOn; + //TODO set default empty values if not exist + private String notes = ""; + private List<String> labels = new ArrayList<>(); + + public void setLabels(Object labels) { + if(labels instanceof List) + this.labels = (List<String>) labels; + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifact.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifact.java new file mode 100644 index 0000000..600c735 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifact.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.deploymentartifact; + +import lombok.Data; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.Map; + +/** + * A model class which represents Deployment-Artifact entity + */ +@Data +@Document("deployment-artifact") +public class DeploymentArtifact { + + private String id; + + private Integer version; + + private String content; + + private String fileName; + + private DeploymentArtifactStatus status; + + private Map<String, Object> metadata; + + private MsInstanceInfo msInstanceInfo; + + private Map<String, Object> specificationInfo; + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactFilter.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactFilter.java new file mode 100644 index 0000000..870ca46 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactFilter.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.deploymentartifact; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * A model class to construct a filter that can be passed in DeploymentArtifactSearch + * @see org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactSearch + */ +@Data +public class DeploymentArtifactFilter { + @JsonProperty("release") + private String release; + + @JsonProperty("status") + private DeploymentArtifactStatus status; + + @JsonProperty("tag") + private String tag; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactSearch.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactSearch.java new file mode 100644 index 0000000..9e955cd --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactSearch.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.deploymentartifact; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * A model class to define Deployment-Artifact's searching criteria. + */ +@Data +public class DeploymentArtifactSearch { + + @JsonProperty("filter") + private DeploymentArtifactFilter filter; + + public DeploymentArtifactSearch() { + this.filter = new DeploymentArtifactFilter(); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactStatus.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactStatus.java new file mode 100644 index 0000000..4ee4e0e --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/DeploymentArtifactStatus.java @@ -0,0 +1,30 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.deploymentartifact; + +/** + * Supported Statuses for a Deployment-Artifact + */ +public enum DeploymentArtifactStatus { + + IN_DEV, NOT_NEEDED, DEV_COMPLETE, + IN_PROD, PROD_FAILED +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/MsInstanceInfo.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/MsInstanceInfo.java new file mode 100644 index 0000000..665961c --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/deploymentartifact/MsInstanceInfo.java @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.deploymentartifact; + +import lombok.Data; + +/** + * MsInstance Reference model used in DeploymentArtifact entity + */ +@Data +public class MsInstanceInfo { + String id; + String name; + String release; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ErrorMessages.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ErrorMessages.java new file mode 100644 index 0000000..9b96066 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ErrorMessages.java @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions; + +public class ErrorMessages { + + public static final String MICROSERVICE_NAME_CONFLICT_MESSAGE = "Microservice with this name already exists."; + public static final String MICROSERVICE_TAG_CONFLICT_MESSAGE = "Microservice with this tag name already exists."; + public static final String MS_TAG_NAME_VALIDATION_MESSAGE = + "Microservice tag name is Invalid. Accepts lowercase letters and hyphens." + + " Tag name length cannot exceed 50 characters"; + public static final String MS_SERVICE_NAME_CONFLICT_MESSAGE = "Microservice with this core name already exists."; + public static final String MS_SERVICE_NAME_VALIDATION_MESSAGE = + "Service name is Invalid. Accepts lowercase letters and hyphens"; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/MissingRequestBodyException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/MissingRequestBodyException.java new file mode 100644 index 0000000..2d7d785 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/MissingRequestBodyException.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions; + +public class MissingRequestBodyException extends RuntimeException { +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/OperationNotAllowedException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/OperationNotAllowedException.java new file mode 100644 index 0000000..47dafc9 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/OperationNotAllowedException.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions; + +public class OperationNotAllowedException extends RuntimeException { + public OperationNotAllowedException(String message) { + super(message); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ReleaseNotSupportedException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ReleaseNotSupportedException.java new file mode 100644 index 0000000..7ea6834 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ReleaseNotSupportedException.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions; + +public class ReleaseNotSupportedException extends RuntimeException{ +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ResourceConflictException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ResourceConflictException.java new file mode 100644 index 0000000..d81c68c --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/ResourceConflictException.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions; + +public class ResourceConflictException extends RuntimeException{ + public ResourceConflictException(String message) { + super(message); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceNotFoundException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceNotFoundException.java new file mode 100644 index 0000000..3ee81e4 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceNotFoundException.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.basemicroservice; + +public class BaseMicroserviceNotFoundException extends RuntimeException { + public BaseMicroserviceNotFoundException(String message) { + super(message); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceTagAlreadyExists.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceTagAlreadyExists.java new file mode 100644 index 0000000..e0bd119 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceTagAlreadyExists.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.basemicroservice; + +public class BaseMicroserviceTagAlreadyExists extends RuntimeException { +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceTagInvalid.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceTagInvalid.java new file mode 100644 index 0000000..79282aa --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMicroserviceTagInvalid.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.basemicroservice; + +public class BaseMicroserviceTagInvalid extends RuntimeException { +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMsServiceNameAlreadyExists.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMsServiceNameAlreadyExists.java new file mode 100644 index 0000000..3ae1b6f --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMsServiceNameAlreadyExists.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.basemicroservice; + +public class BaseMsServiceNameAlreadyExists extends RuntimeException { +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMsServiceNameInvalid.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMsServiceNameInvalid.java new file mode 100644 index 0000000..6de3014 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/basemicroservice/BaseMsServiceNameInvalid.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.basemicroservice; + +public class BaseMsServiceNameInvalid extends RuntimeException { +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/common/UserNotPassedException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/common/UserNotPassedException.java new file mode 100644 index 0000000..b34e065 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/common/UserNotPassedException.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.common; + +public class UserNotPassedException extends RuntimeException { + public UserNotPassedException(String message) { + super(message); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/BlueprintFileNameCreateException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/BlueprintFileNameCreateException.java new file mode 100644 index 0000000..5f52885 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/BlueprintFileNameCreateException.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact; + +public class BlueprintFileNameCreateException extends RuntimeException{ + public BlueprintFileNameCreateException(String message) { + super(message); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/DeploymentArtifactNotFound.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/DeploymentArtifactNotFound.java new file mode 100644 index 0000000..e10c54e --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/DeploymentArtifactNotFound.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact; + +public class DeploymentArtifactNotFound extends RuntimeException{ + public DeploymentArtifactNotFound(String message) { + super(message); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/StatusChangeNotValidException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/StatusChangeNotValidException.java new file mode 100644 index 0000000..99faf50 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/deploymentartifact/StatusChangeNotValidException.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact; + +public class StatusChangeNotValidException extends RuntimeException { + + public StatusChangeNotValidException(String message) { + super(message); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/msinstance/MsInstanceAlreadyExistsException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/msinstance/MsInstanceAlreadyExistsException.java new file mode 100644 index 0000000..80778ea --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/msinstance/MsInstanceAlreadyExistsException.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.msinstance; + +public class MsInstanceAlreadyExistsException extends RuntimeException { +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/msinstance/MsInstanceNotFoundException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/msinstance/MsInstanceNotFoundException.java new file mode 100644 index 0000000..9ea977c --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/msinstance/MsInstanceNotFoundException.java @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.msinstance; + +public class MsInstanceNotFoundException extends RuntimeException{ + public MsInstanceNotFoundException(String message) { + super(message); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/specification/SpecificationInvalid.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/specification/SpecificationInvalid.java new file mode 100644 index 0000000..1b56d35 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/specification/SpecificationInvalid.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.specification; + +import java.util.Map; + +public class SpecificationInvalid extends RuntimeException { + + Map<String, Object> errorsMap; + + public SpecificationInvalid(String message) { + super(message); + } + + public SpecificationInvalid(Map<String, Object> errorsMap){ + this.errorsMap = errorsMap; + } + + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/specification/SpecificationNotFoundException.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/specification/SpecificationNotFoundException.java new file mode 100644 index 0000000..9728b15 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/exceptions/specification/SpecificationNotFoundException.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.exceptions.specification; + +public class SpecificationNotFoundException extends RuntimeException { +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/DeploymentArtifactsRef.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/DeploymentArtifactsRef.java new file mode 100644 index 0000000..fe1aed5 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/DeploymentArtifactsRef.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.microserviceinstance; + +import lombok.Data; + +import java.util.List; + +/** + * DeploymentArtifacts Reference model used in Microservice-Instance entity + */ +@Data +public class DeploymentArtifactsRef { + + private int mostRecentVersion; + private List<String> deploymentArtifacts; + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/MsInstance.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/MsInstance.java new file mode 100644 index 0000000..d305aa4 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/MsInstance.java @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.microserviceinstance; + +import org.onap.dcaegen2.platform.mod.model.specification.Specification; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.DBRef; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.Map; + +/** + * A model class which represents Microservice-Instance entity + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Document("ms-instance") +public class MsInstance { + @Id + private String id; + private String name; + private String release; + private String version; + private MsInstanceStatus status; + private Map<String, Object> metadata; + private Map<String,Object> msInfo; + + @DBRef + private Specification activeSpec; + + private DeploymentArtifactsRef deploymentArtifactsInfo; +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/MsInstanceStatus.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/MsInstanceStatus.java new file mode 100644 index 0000000..223f3dc --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/microserviceinstance/MsInstanceStatus.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.microserviceinstance; + +/** + * Supported Statuses for Microservice-Instance entity + */ +public enum MsInstanceStatus { + NEW, IN_DEV, DEV_COMPLETE, IN_TEST, CERTIFIED, PROD_DEPLOYED +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/DeploymentArtifactPatchRequest.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/DeploymentArtifactPatchRequest.java new file mode 100644 index 0000000..8d52488 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/DeploymentArtifactPatchRequest.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.Map; + +/** + * A model that represent request body to patch DeploymentArtifact entity. + */ +@Data +public class DeploymentArtifactPatchRequest { + + @JsonProperty("status") + private DeploymentArtifactStatus status; + + @JsonProperty("metadata") + private Map<String, Object> metaData; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/ErrorResponse.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/ErrorResponse.java new file mode 100644 index 0000000..fe78f94 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/ErrorResponse.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * A model that represent response body to send a simple error response. + */ +@Data +@AllArgsConstructor +public class ErrorResponse { + + private String message; + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/GenericErrorResponse.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/GenericErrorResponse.java new file mode 100644 index 0000000..76597e2 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/GenericErrorResponse.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import lombok.Data; +import org.springframework.http.HttpStatus; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * A model that represent response body to send a detailed error response. + */ +@Data +public class GenericErrorResponse { + private List<String> errors = new ArrayList<>(); + private HttpStatus status; + private String message; + + public GenericErrorResponse() { + } + + public GenericErrorResponse(List<String> errors, HttpStatus status, String message) { + this.errors = errors; + this.status = status; + this.message = message; + } + + public GenericErrorResponse(String error, HttpStatus status, String message) { + this.status = status; + this.message = message; + errors = Arrays.asList(error); + } + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MicroserviceCreateRequest.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MicroserviceCreateRequest.java new file mode 100644 index 0000000..f8288cb --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MicroserviceCreateRequest.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMsLocation; +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMsType; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import java.util.Map; + +/** + * A model that represent request body to create a Microservice entity. + */ +@NoArgsConstructor +@Data +public class MicroserviceCreateRequest { + + @NotBlank(message = "Microservice tag can not be blank") + @Pattern(regexp = "^([a-z0-9](-[a-z0-9])*)+$", message = "Microservice tag name is Invalid. Accepts alphanumerics and hyphens.") + @Size(min = 5, max = 50, message = "Tag name length cannot exceed 50 characters") + private String tag; + + @NotBlank(message = "Microservice name cannot be blank") + private String name; + + @Pattern(regexp = "^[a-z-]*$", message = "Microservice core name is Invalid. Accepts lowercase letters and hyphens.") + private String serviceName; + + private BaseMsType type; + private BaseMsLocation location; + private String namespace; + private Map<String, Object> metadata; + + @NotBlank(message = "user can not be blank") + private String user; + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MicroserviceUpdateRequest.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MicroserviceUpdateRequest.java new file mode 100644 index 0000000..a7262d6 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MicroserviceUpdateRequest.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMsLocation; +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMsType; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; +import java.util.Map; + +/** + * A model that represent request body to update a Microservice entity. + */ +@NoArgsConstructor +@Data +public class MicroserviceUpdateRequest { + + @Pattern(regexp = "^(?!\\s*$).+", message = "must not be blank") + private String name; + + @Pattern(regexp = "^[a-z-]*$", message = "Microservice core name is Invalid. Accepts lowercase letters and hyphens.") + private String serviceName; + + private BaseMsType type; + private BaseMsLocation location; + private String namespace; + private Map<String, Object> metadata; + + @NotBlank(message = "user cannot be blank") + private String user; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MsInstanceRequest.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MsInstanceRequest.java new file mode 100644 index 0000000..803d417 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MsInstanceRequest.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import java.util.Map; + +/** + * A model that represent request body to create MsInsance entity. + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MsInstanceRequest { + + @NotBlank + private String name; + + @NotBlank + private String release; + + private String version; + + @NotBlank + private String user; + + private Map<String,Object> metadata; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MsInstanceUpdateRequest.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MsInstanceUpdateRequest.java new file mode 100644 index 0000000..2af61a8 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/MsInstanceUpdateRequest.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.util.Map; + +/** + * A model that represent request body to patch MsInstance entity. + */ +@Data +public class MsInstanceUpdateRequest { + + private String release; + private String version; + private Map<String,Object> metadata; + + @NotBlank(message = "User cannot be blank.") + private String user; +} + + diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/SpecificationRequest.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/SpecificationRequest.java new file mode 100644 index 0000000..e34379e --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/SpecificationRequest.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import org.onap.dcaegen2.platform.mod.model.specification.DeploymentType; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * A model that represent request body to create Specification entity. + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class SpecificationRequest { + + private Map<String,Object> specContent; + private Map<String, Object> policyJson; + private DeploymentType type; + private String user; + private Map<String,Object> metadata; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/SuccessResponse.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/SuccessResponse.java new file mode 100644 index 0000000..d428407 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/restapi/SuccessResponse.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.restapi; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * A model that represent a simple Success response body. + */ +@Data +@AllArgsConstructor +public class SuccessResponse { + + private String message; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/DeploymentType.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/DeploymentType.java new file mode 100644 index 0000000..815a529 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/DeploymentType.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.specification; + +/** + * Supported Deployment Types in Specification entity + */ +public enum DeploymentType { + K8S, DOCKER +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/Specification.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/Specification.java new file mode 100644 index 0000000..32778a3 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/Specification.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.specification; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.Map; + +/** + * A model class which represents Specification entity + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@Document("specification") +public class Specification { + + @Id + private String id; + private SpecificationStatus status; + private Map<String,Object> specContent; + private Map<String, Object> policyJson; + private DeploymentType type; + private Map<String,Object> metadata; + private Map<String,Object> msInstanceInfo; +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/SpecificationStatus.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/SpecificationStatus.java new file mode 100644 index 0000000..3e6cd1a --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/model/specification/SpecificationStatus.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.model.specification; + +/** + * Supported statuses for Specification entity + */ +public enum SpecificationStatus { + ACTIVE, INACTIVE +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/basemicroservice/BaseMicroserviceMongoGateway.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/basemicroservice/BaseMicroserviceMongoGateway.java new file mode 100644 index 0000000..9101234 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/basemicroservice/BaseMicroserviceMongoGateway.java @@ -0,0 +1,71 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mongo.basemicroservice; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMicroservice; +import org.onap.dcaegen2.platform.mod.web.service.basemicroservice.BaseMicroserviceGateway; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +/** + * Mongo implementation of BaseMicroserviceGateway + */ +@Service +public class BaseMicroserviceMongoGateway implements BaseMicroserviceGateway { + + @Autowired + BaseMicroserviceMongoRepo repo; + + @Override + public Optional<BaseMicroservice> findByName(String name) { + return repo.findByNameIgnoreCase(name); + } + + @Override + public Optional<BaseMicroservice> findByTag(String tag) { + return repo.findByTagIgnoreCase(tag); + } + + @Override + public Optional<BaseMicroservice> findByServiceName(String serviceName) { + return repo.findByServiceNameIgnoreCase(serviceName); + } + + @Override + public BaseMicroservice save(BaseMicroservice microservice) { + return repo.save(microservice); + } + + @Override + public List<BaseMicroservice> findAll() { + Sort sortByCreatedDate = Sort.by(Sort.Direction.DESC, "metadata.createdOn"); + return repo.findAll(sortByCreatedDate); + } + + @Override + public Optional<BaseMicroservice> findById(String msId) { + return Optional.empty(); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/basemicroservice/BaseMicroserviceMongoRepo.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/basemicroservice/BaseMicroserviceMongoRepo.java new file mode 100644 index 0000000..b3795b2 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/basemicroservice/BaseMicroserviceMongoRepo.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mongo.basemicroservice; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMicroservice; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +/** + * An interface to use Spring MongoRepository + */ +@Repository +public interface BaseMicroserviceMongoRepo extends MongoRepository<BaseMicroservice, String> { + + Optional<BaseMicroservice> findByNameIgnoreCase(String name); + + Optional<BaseMicroservice> findByTagIgnoreCase(String tag); + + Optional<BaseMicroservice> findByServiceNameIgnoreCase(String serviceName); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/deploymentartifact/DeploymentArtifactMongoGateway.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/deploymentartifact/DeploymentArtifactMongoGateway.java new file mode 100644 index 0000000..72e9ec6 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/deploymentartifact/DeploymentArtifactMongoGateway.java @@ -0,0 +1,86 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mongo.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactSearch; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.MsInstanceInfo; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactGateway; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +/** + * Mongo implementation of BaseMicroserviceGateway + */ +@Service +public class DeploymentArtifactMongoGateway implements DeploymentArtifactGateway { + + @Autowired + DeploymentArtifactMongoRepo crudRepo; + + public DeploymentArtifactMongoGateway(DeploymentArtifactMongoRepo repo) { + this.crudRepo = repo; + } + + @Override + public List<DeploymentArtifact> findAll() { + return crudRepo.findAll(); + } + + @Override + public List<DeploymentArtifact> findByMsInstanceId(String id) { + return crudRepo.findByMsInstanceInfo_Id(id); + } + + @Override + public Optional<DeploymentArtifact> findById(String id) { + return crudRepo.findById(id); + } + + @Override + public void deleteById(String deploymentArtifactId) { + crudRepo.deleteById(deploymentArtifactId); + } + + @Override + public DeploymentArtifact save(DeploymentArtifact deploymentArtifact) { + return crudRepo.save(deploymentArtifact); + } + + @Override + public List<DeploymentArtifact> findAll(DeploymentArtifactSearch search) { + DeploymentArtifact artifact = new DeploymentArtifact(); + artifact.setStatus(search.getFilter().getStatus()); + //Currently searching tag in filename as it is not present in DeploymentArtifact record + artifact.setFileName(search.getFilter().getTag()); + + MsInstanceInfo msInstanceInfo = new MsInstanceInfo(); + msInstanceInfo.setRelease(search.getFilter().getRelease()); + artifact.setMsInstanceInfo(msInstanceInfo); + + return crudRepo.findAll(Example.of(artifact,ExampleMatcher.matching().withIgnoreCase())); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/deploymentartifact/DeploymentArtifactMongoRepo.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/deploymentartifact/DeploymentArtifactMongoRepo.java new file mode 100644 index 0000000..cb8d0bb --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/deploymentartifact/DeploymentArtifactMongoRepo.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mongo.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * An interface to use Spring MongoRepository + */ +@Repository +public interface DeploymentArtifactMongoRepo extends MongoRepository<DeploymentArtifact, String> { + + List<DeploymentArtifact> findByMsInstanceInfo_Id(String id); + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/microserviceinstance/MsInstanceMongoGateway.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/microserviceinstance/MsInstanceMongoGateway.java new file mode 100644 index 0000000..d6d0d35 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/microserviceinstance/MsInstanceMongoGateway.java @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mongo.microserviceinstance; + +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.web.service.microserviceinstance.MsInstanceGateway; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +/** + * Mongo implementation of MsInstance + */ +@Service +public class MsInstanceMongoGateway implements MsInstanceGateway { + + @Autowired + private MsInstanceMongoRepo repo; + + @Override + public Optional<MsInstance> findByNameAndRelease(String name, String release) { + return repo.findByNameIgnoreCaseAndReleaseIgnoreCase(name, release); + } + + @Override + public Optional<MsInstance> findById(String msInstanceId) { + return repo.findById(msInstanceId); + } + + @Override + public List<MsInstance> findAll() { + Sort sortByCreatedDate = Sort.by(Sort.Direction.DESC, "metadata.createdOn"); + return repo.findAll(sortByCreatedDate); + } + + @Override + public MsInstance save(MsInstance msInstance) { + return repo.save(msInstance); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/microserviceinstance/MsInstanceMongoRepo.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/microserviceinstance/MsInstanceMongoRepo.java new file mode 100644 index 0000000..1d6a277 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/microserviceinstance/MsInstanceMongoRepo.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mongo.microserviceinstance; + +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +/** + * An interface to use Spring MongoRepository + */ +@Repository +public interface MsInstanceMongoRepo extends MongoRepository<MsInstance, String> { + + Optional<MsInstance> findByNameIgnoreCaseAndReleaseIgnoreCase(String name, String release); + + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/specification/SpecificationMongoGateway.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/specification/SpecificationMongoGateway.java new file mode 100644 index 0000000..ae3a421 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/specification/SpecificationMongoGateway.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mongo.specification; + +import org.onap.dcaegen2.platform.mod.model.specification.Specification; +import org.onap.dcaegen2.platform.mod.web.service.specification.SpecificationGateway; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * Mongo implementation of Specification + */ +@Service +public class SpecificationMongoGateway implements SpecificationGateway { + + @Autowired + private SpecificationMongoRepo repo; + + @Override + public List<Specification> getSpecificationByMsInstanceId(String id) { + return repo.getSpecificationsByMsInstaceId(id); + } + + @Override + public Specification save(Specification newSpec) { + return repo.save(newSpec); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/specification/SpecificationMongoRepo.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/specification/SpecificationMongoRepo.java new file mode 100644 index 0000000..306e78a --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/mongo/specification/SpecificationMongoRepo.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.mongo.specification; + +import org.onap.dcaegen2.platform.mod.model.specification.Specification; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.data.mongodb.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * An interface to use Spring MongoRepository + */ +@Repository +public interface SpecificationMongoRepo extends MongoRepository<Specification, String> { + + @Query(value = "{'msInstanceInfo.id':?0}") + List<Specification> getSpecificationsByMsInstaceId(String id); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java new file mode 100644 index 0000000..1a2f5f9 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/AppExceptionHandler.java @@ -0,0 +1,149 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.controller; + +import org.onap.dcaegen2.platform.mod.model.exceptions.MissingRequestBodyException; +import org.onap.dcaegen2.platform.mod.model.exceptions.OperationNotAllowedException; +import org.onap.dcaegen2.platform.mod.model.exceptions.ResourceConflictException; +import org.onap.dcaegen2.platform.mod.model.exceptions.basemicroservice.BaseMicroserviceNotFoundException; +import org.onap.dcaegen2.platform.mod.model.exceptions.common.UserNotPassedException; +import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.DeploymentArtifactNotFound; +import org.onap.dcaegen2.platform.mod.model.exceptions.msinstance.MsInstanceNotFoundException; +import org.onap.dcaegen2.platform.mod.model.exceptions.specification.SpecificationInvalid; +import org.onap.dcaegen2.platform.mod.model.restapi.ErrorResponse; +import org.onap.dcaegen2.platform.mod.model.restapi.GenericErrorResponse; +import com.fasterxml.jackson.core.JsonParseException; +import com.google.gson.Gson; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * a class to manage all exceptions + */ +@ControllerAdvice +@Slf4j +public class AppExceptionHandler { + + @ExceptionHandler(value = {WebClientResponseException.class}) + public ResponseEntity<ErrorResponse> handleCompSpecInvalidException + (WebClientResponseException ex, WebRequest request) { + return new ResponseEntity<ErrorResponse> + (new ErrorResponse(ex.getResponseBodyAsString()), HttpStatus.INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler(value = {JsonParseException.class}) + public ResponseEntity<GenericErrorResponse> handleJsonParsedException + (JsonParseException ex, WebRequest request) { + + GenericErrorResponse response = new GenericErrorResponse(); + response.setStatus(HttpStatus.BAD_REQUEST); + response.setMessage("Invalid JSON request body format."); + response.setErrors(Arrays.asList(ex.getMessage())); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler + public ResponseEntity<GenericErrorResponse> specificationInvalid(SpecificationInvalid ex) { + Map<String, Object> errorResponse = new Gson().fromJson(ex.getMessage(), Map.class); + GenericErrorResponse response = new GenericErrorResponse(); + response.setMessage((String) errorResponse.get("summary")); + response.setStatus(HttpStatus.BAD_REQUEST); + response.setErrors((List<String>) errorResponse.get("errors")); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler + public ResponseEntity<GenericErrorResponse> missingRequestBodyException(MissingRequestBodyException ex){ + GenericErrorResponse response = new GenericErrorResponse(); + response.setMessage("Missing paramaters"); + response.setStatus(HttpStatus.BAD_REQUEST); + response.setErrors(Arrays.asList("Missing required request body paramaters")); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler + public ResponseEntity<ErrorResponse> resolveUserNotPassedException(UserNotPassedException ex){ + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler + public ResponseEntity<ErrorResponse> resolveMsInstanceNotFoundException(MsInstanceNotFoundException ex) { + log.error(ex.getMessage()); + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler + public ResponseEntity<ErrorResponse> resolveDeploymentArtifactNotFound(DeploymentArtifactNotFound ex) { + log.error(ex.getMessage()); + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), + HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler + public ResponseEntity<ErrorResponse> resolveOperationNotAllowed(OperationNotAllowedException ex) { + log.error(ex.getMessage()); + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), + HttpStatus.CONFLICT); + } + + @ExceptionHandler + public ResponseEntity<ErrorResponse> resolveResourceConflict(ResourceConflictException ex) { + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.CONFLICT); + } + + @ExceptionHandler(value = {BaseMicroserviceNotFoundException.class}) + public ResponseEntity<ErrorResponse> resolveResourceNotFoundExcetions(RuntimeException ex) { + log.error(ex.getMessage(), ex); + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), HttpStatus.CONFLICT); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity<GenericErrorResponse> resolveBeanValidationException(MethodArgumentNotValidException ex){ + log.error(ex.getMessage()); + GenericErrorResponse response = new GenericErrorResponse(); + response.setMessage("Validation failed."); + response.setStatus(HttpStatus.BAD_REQUEST); + response.setErrors(getBeanValidationErrors(ex)); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + private List<String> getBeanValidationErrors(MethodArgumentNotValidException ex) { + List<String> errors = new ArrayList<>(); + ex.getBindingResult().getAllErrors().forEach((error) -> { + String fieldName = ((FieldError) error).getField(); + String errorMessage = error.getDefaultMessage(); + errors.add(String.format("%s: %s", fieldName, errorMessage)); + }); + return errors; + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/BaseMicroserviceController.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/BaseMicroserviceController.java new file mode 100644 index 0000000..073b93a --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/BaseMicroserviceController.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.controller; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMicroservice; +import org.onap.dcaegen2.platform.mod.model.restapi.MicroserviceCreateRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.MicroserviceUpdateRequest; +import org.onap.dcaegen2.platform.mod.web.service.basemicroservice.MsService; +import io.swagger.annotations.Api; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +import static org.onap.dcaegen2.platform.mod.web.controller.BaseMicroserviceController.API_BASE_MICROSERVICE; + +/** + * Controller class to manage Microservice's REST endpoints + */ +@CrossOrigin +@RestController +@RequestMapping(API_BASE_MICROSERVICE) +@Api(tags = "Base Microservice", description = "APIs to manage Base Microservice") +public class BaseMicroserviceController { + + public static final String API_BASE_MICROSERVICE = "/api/base-microservice"; + @Autowired + @Setter + MsService baseMsService; + + @GetMapping + public List<BaseMicroservice> getAll() { + return baseMsService.getAllMicroservices(); + } + + + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + public BaseMicroservice createMicroservice(@RequestBody @Valid MicroserviceCreateRequest request) { + return baseMsService.createMicroservice(request); + } + + @PatchMapping(value = "/{msId}") + @ResponseStatus(HttpStatus.NO_CONTENT) + public void updateMicroservice(@RequestBody @Valid MicroserviceUpdateRequest request, + @PathVariable("msId") String msId){ + baseMsService.updateMicroservice(msId, request); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/DeploymentArtifactController.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/DeploymentArtifactController.java new file mode 100644 index 0000000..e1cd512 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/DeploymentArtifactController.java @@ -0,0 +1,115 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.controller; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactSearch; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus; +import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.BlueprintFileNameCreateException; +import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.StatusChangeNotValidException; +import org.onap.dcaegen2.platform.mod.model.restapi.DeploymentArtifactPatchRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.ErrorResponse; +import org.onap.dcaegen2.platform.mod.model.restapi.SuccessResponse; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactService; +import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; + +import static org.onap.dcaegen2.platform.mod.web.controller.DeploymentArtifactController.DEPLOYMENT_ARTIFACTS_BASE_URL; + +/** + * Controller class to manage DeploymentArtifact's REST endpoints + */ +@RestController +@CrossOrigin +@RequestMapping(DEPLOYMENT_ARTIFACTS_BASE_URL) +@Slf4j +@Api(tags = "Deployment Artifact", value = "APIs to manage Deployment Artifacts") +public class DeploymentArtifactController { + + public static final String DEPLOYMENT_ARTIFACTS_BASE_URL = "/api/deployment-artifact"; + + public static final String GET_STATUSES = "/statuses"; + + @Autowired + private DeploymentArtifactService service; + + @PostMapping("/{msInstanceId}") + @ResponseStatus(HttpStatus.CREATED) + public DeploymentArtifact generateDeploymentArtifactForMSInstance(@PathVariable String msInstanceId, + @RequestParam String user ){ + return service.generateDeploymentArtifact(msInstanceId, user); + } + + @GetMapping + @ResponseStatus(HttpStatus.OK) + public List<DeploymentArtifact> getAllDeploymentArtifacts(){ + return service.getAllDeploymentArtifacts(); + } + + @PostMapping("/search") + @ResponseStatus(HttpStatus.OK) + public List<DeploymentArtifact> searchDeploymentArtifacts(@RequestBody DeploymentArtifactSearch searchRequest){ + log.info("Search on deployment artifacts: {}", searchRequest); + return service.searchDeploymentArtifacts(searchRequest); + } + + @GetMapping(GET_STATUSES) + @ResponseStatus(HttpStatus.OK) + public List<DeploymentArtifactStatus> getDeploymentArtifactStatuses(){ + return Arrays.asList(DeploymentArtifactStatus.values()); + } + + @PatchMapping(value = "/{deploymentArtifactId}", params = {"user!="}) + public ResponseEntity<SuccessResponse> patchDeploymentArtifact(@PathVariable("deploymentArtifactId") String id, + @RequestBody DeploymentArtifactPatchRequest deploymentArtifactPatchRequest, + @RequestParam("user") String user){ + log.info("***Received request {} to update DeploymentArtifact id {} by {}", deploymentArtifactPatchRequest, id, user); + service.updateDeploymentArtifact(id, deploymentArtifactPatchRequest, user); + return new ResponseEntity<>(new SuccessResponse("Deployment Artifact was updated."),HttpStatus.OK); + } + + @DeleteMapping( value = "/{deploymentArtifactId}", params = {"user!="}) + public ResponseEntity<SuccessResponse> deleteDeploymentArtifact(@PathVariable("deploymentArtifactId") String id, + @RequestParam("user") String user){ + log.info("***Received request to delete DeploymentArtifact id {} by {}", id, user); + service.deleteDeploymentArtifact(id); + return new ResponseEntity<>(new SuccessResponse("Deployment Artifact was deleted"), HttpStatus.OK); + } + + @ExceptionHandler + public ResponseEntity<ErrorResponse> resolveBaseMsServiceNameRegex(BlueprintFileNameCreateException ex) { + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), + HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler + public ResponseEntity<ErrorResponse> resolveStatusValidationFailure(StatusChangeNotValidException ex) { + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), + HttpStatus.BAD_REQUEST); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/MicroserviceInstanceController.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/MicroserviceInstanceController.java new file mode 100644 index 0000000..14eb154 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/MicroserviceInstanceController.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.controller; + +import org.onap.dcaegen2.platform.mod.model.exceptions.msinstance.MsInstanceAlreadyExistsException; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.restapi.ErrorResponse; +import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceUpdateRequest; +import org.onap.dcaegen2.platform.mod.web.service.microserviceinstance.MsInstanceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * Controller class to manage MicroserviceInstance's REST endpoints + */ +@CrossOrigin +@RestController +@Api(tags = "Microservice Instance", description = "APIs to manage Microservice Instance") +@RequestMapping("/api/microservice-instance") +public class MicroserviceInstanceController { + + @Autowired + MsInstanceService msInstanceService; + + @GetMapping + @ApiOperation("Get all Microservices Instances") + public List<MsInstance> getAll() { + return msInstanceService.getAll(); + } + + + @PostMapping("/{msName}") + @ApiOperation("Create a Microservice Instance") + @ResponseStatus(HttpStatus.CREATED) + public MsInstance createMsInstance(@PathVariable String msName, @RequestBody MsInstanceRequest request) { + return msInstanceService.createMicroserviceInstance(msName, request); + } + + @PatchMapping("/{msId}") + @ApiOperation("Patch a Microservice Instance") + @ResponseStatus(HttpStatus.OK) + public MsInstance patchMsInstance(@RequestBody MsInstanceUpdateRequest request, @PathVariable String msId){ + return msInstanceService.updateMsInstance(request, msId); + } + + @ExceptionHandler + public ResponseEntity<ErrorResponse> resolveMsInstanceConflict(MsInstanceAlreadyExistsException ex) { + return new ResponseEntity<>(new ErrorResponse("Microservice Instance for the given name and release already exists"), HttpStatus.CONFLICT); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/SpecificationController.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/SpecificationController.java new file mode 100644 index 0000000..854e7e6 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/controller/SpecificationController.java @@ -0,0 +1,62 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.controller; + +import org.onap.dcaegen2.platform.mod.model.restapi.SpecificationRequest; +import org.onap.dcaegen2.platform.mod.model.specification.Specification; +import org.onap.dcaegen2.platform.mod.web.service.specification.SpecificationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * Controller class to manage Specification's REST endpoints + */ +@CrossOrigin +@RestController +@Api(tags = "Component Specification", description = "APIs to manage Component Specifications") +@RequestMapping("/api/specification") +@Slf4j +public class SpecificationController { + + @Autowired + SpecificationService specificationService; + + @GetMapping("/{msInstanceId}") + @ApiOperation("Get all specifications for a Microservice Instance") + public List<Specification> getAllSpecsByMsInstanceId(@PathVariable String msInstanceId) { + log.info(msInstanceId); + return specificationService.getAllSpecsByMsInstanceId(msInstanceId); + } + + @PostMapping("/{msInstanceId}") + @ApiOperation("Create Specification for a Microservice Instance") + @ResponseStatus(HttpStatus.CREATED) + public Specification createSpecification(@PathVariable String msInstanceId, @RequestBody SpecificationRequest request) { + log.info(request.toString()); + return specificationService.createSpecification(msInstanceId, request); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/BaseMicroserviceGateway.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/BaseMicroserviceGateway.java new file mode 100644 index 0000000..a516d90 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/BaseMicroserviceGateway.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.basemicroservice; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMicroservice; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +/** + * An interface to interact with BaseMicroservice persistence + */ +public interface BaseMicroserviceGateway { + + List<BaseMicroservice> findAll(); + + Optional<BaseMicroservice> findByName(String name); + + Optional<BaseMicroservice> findByTag(String tag); + + Optional<BaseMicroservice> findByServiceName(String serviceName); + + BaseMicroservice save(BaseMicroservice microservice); + + Optional<BaseMicroservice> findById(String msId); +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/MsService.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/MsService.java new file mode 100644 index 0000000..cdc1921 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/MsService.java @@ -0,0 +1,47 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.basemicroservice; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMicroservice; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.restapi.MicroserviceCreateRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.MicroserviceUpdateRequest; + +import java.util.List; + +/** + * An interface to access Ms Services + */ +public interface MsService { + BaseMicroservice createMicroservice(MicroserviceCreateRequest microserviceRequest); + + List<BaseMicroservice> getAllMicroservices(); + + BaseMicroservice getMicroserviceById(String baseMsId); + + BaseMicroservice getMicroserviceByName(String msName); + + void updateMicroservice(String requestedMsId, MicroserviceUpdateRequest updateRequest); + + void saveMsInstanceReferenceToMs(BaseMicroservice microservice, MsInstance msInstance); + + void updateMsInstanceRef(MsInstance msInstance); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/MsServiceImpl.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/MsServiceImpl.java new file mode 100644 index 0000000..9cf46e6 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/basemicroservice/MsServiceImpl.java @@ -0,0 +1,257 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.basemicroservice; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMicroservice; +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMsStatus; +import org.onap.dcaegen2.platform.mod.model.common.AuditFields; +import org.onap.dcaegen2.platform.mod.model.exceptions.ErrorMessages; +import org.onap.dcaegen2.platform.mod.model.exceptions.ResourceConflictException; +import org.onap.dcaegen2.platform.mod.model.exceptions.basemicroservice.BaseMicroserviceNotFoundException; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.restapi.MicroserviceCreateRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.MicroserviceUpdateRequest; +import org.onap.dcaegen2.platform.mod.web.service.microserviceinstance.MsInstanceService; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * MsService implementation + */ +@Service +public class MsServiceImpl implements MsService { + + @Autowired + @Setter + private BaseMicroserviceGateway repository; + + @Autowired + @Setter + private MsInstanceService msInstanceService; + + /** + * creates Microservice record + * @param microserviceRequest + * @return + */ + @Override + public BaseMicroservice createMicroservice(MicroserviceCreateRequest microserviceRequest) { + checkIfThereAreAnyConflicts(microserviceRequest); //TODO: Make fields unique in entity itself + BaseMicroservice microservice = new BaseMsCreator().create(microserviceRequest); + return repository.save(microservice); + } + + /** + * name, tag and serviceName are unique for the given ms. This method make sure that. + * */ + private void checkIfThereAreAnyConflicts(MicroserviceCreateRequest microserviceRequest) { + checkIfMsNameAlreadyExists(microserviceRequest.getName()); + checkIfMsTagAlreadyExists(microserviceRequest.getTag()); + checkiIfServiceNameAlreadyExists(microserviceRequest.getServiceName()); + } + + private void checkIfMsNameAlreadyExists(String msName) { + if (repository.findByName(msName).isPresent()) + throw new ResourceConflictException(ErrorMessages.MICROSERVICE_NAME_CONFLICT_MESSAGE); + } + + private void checkIfMsTagAlreadyExists(String msTag) { + if (repository.findByTag(msTag).isPresent()) + throw new ResourceConflictException(ErrorMessages.MICROSERVICE_TAG_CONFLICT_MESSAGE); + } + + private void checkiIfServiceNameAlreadyExists(String serviceName) { + boolean serviceNameIsEmpty = serviceName == null || serviceName.isEmpty(); + if(serviceNameIsEmpty) + return; + if (repository.findByServiceName(serviceName).isPresent()) + throw new ResourceConflictException(ErrorMessages.MS_SERVICE_NAME_CONFLICT_MESSAGE); + } + + /** + * lists all microservice records + * @return + */ + @Override + public List<BaseMicroservice> getAllMicroservices() { + return repository.findAll(); + } + + /** + * gets a Mioroservice by id + * @param baseMsId + * @return + */ + @Override + public BaseMicroservice getMicroserviceById(String baseMsId) { + return repository.findById(baseMsId).orElseThrow(() -> + new BaseMicroserviceNotFoundException(String.format("Microservice with id %s not found", baseMsId))); + } + + /** + * gets a Microservice by name + * @param msName + * @return + */ + @Override + public BaseMicroservice getMicroserviceByName(String msName) { + return repository.findByName(msName).orElseThrow(() -> + new BaseMicroserviceNotFoundException(String.format("Microservice with name %s not found", msName))); + } + + /** + * updates a Microservice + * @param requestedMsId + * @param updateRequest + */ + @Override + public void updateMicroservice(String requestedMsId, MicroserviceUpdateRequest updateRequest) { + BaseMicroservice microservice = getMicroserviceById(requestedMsId); + updateMetadata(updateRequest, microservice); + updateOtherFields(updateRequest, microservice); + repository.save(microservice); + msInstanceService.updateMicroserviceReference(microservice); + } + + //TODO: Get rid of nulls! + private void updateMetadata(MicroserviceUpdateRequest updateRequest, BaseMicroservice microservice) { + if(updateRequest.getUser() != null){ + microservice.getMetadata().setUpdatedBy(updateRequest.getUser()); + } + if(updateRequest.getMetadata() != null && updateRequest.getMetadata().containsKey("notes")){ + microservice.getMetadata().setNotes((String) updateRequest.getMetadata().get("notes")); + } + if(updateRequest.getMetadata() != null && updateRequest.getMetadata().containsKey("labels")){ + microservice.getMetadata().setLabels((List<String>) updateRequest.getMetadata().get("labels")); + } + microservice.getMetadata().setUpdatedOn(new Date()); + } + + private void updateOtherFields(MicroserviceUpdateRequest updateRequest, BaseMicroservice microservice) { + if(updateRequest.getName() != null){ + updateName(updateRequest, microservice); + } + if(updateRequest.getType() != null){ + microservice.setType(updateRequest.getType()); + } + if(updateRequest.getLocation() != null){ + microservice.setLocation(updateRequest.getLocation()); + } + if(updateRequest.getServiceName() != null){ + updateServiceName(updateRequest, microservice); + } + if(updateRequest.getNamespace() != null){ + microservice.setNamespace(updateRequest.getNamespace()); + } + } + + /** + * If name requested in the updateRequest doesn't match the name of the ms record which is being worked on, + * then only check for the uniqueness. + */ + private void updateName(MicroserviceUpdateRequest updateRequest, BaseMicroservice microservice) { + boolean notMatchesWithCurrentName = !updateRequest.getName().equals(microservice.getName()); + if(notMatchesWithCurrentName) + checkIfMsNameAlreadyExists(updateRequest.getName()); + microservice.setName(updateRequest.getName()); + } + + /** + * If serviceName requested in the updateRequest doesn't match the serviceName of the ms record which is + * being worked on, then only check for the uniqueness. + */ + private void updateServiceName(MicroserviceUpdateRequest updateRequest, BaseMicroservice microservice) { + boolean notMatchesWithCurrentServiceName = !updateRequest.getServiceName().equals(microservice.getServiceName()); + if(notMatchesWithCurrentServiceName) + checkiIfServiceNameAlreadyExists(updateRequest.getServiceName()); + microservice.setServiceName(updateRequest.getServiceName()); + } + + /** + * saves msInstance reference in a given Microservice + * @param microservice + * @param msInstance + */ + @Override + public void saveMsInstanceReferenceToMs(BaseMicroservice microservice, MsInstance msInstance) { + microservice.getMsInstances().add(getMsInstanceReference(msInstance)); + repository.save(microservice); + } + + /** + * updates MsIntstance ref in Microservice record + * @param msInstance + */ + @Override + public void updateMsInstanceRef(MsInstance msInstance) { + BaseMicroservice microservice = getMicroserviceById((String) msInstance.getMsInfo().get("id")); + List<Map<String, String>> msInstancesRef = microservice.getMsInstances(); + msInstancesRef.forEach((ref) -> { + if(ref.get("id").equals(msInstance.getId())) + ref.put("name", msInstance.getName()); + }); + repository.save(microservice); + } + + private Map<String, String> getMsInstanceReference(MsInstance msInstance) { + Map<String,String> msInstanceInfo = new HashMap<>(); + msInstanceInfo.put("id", msInstance.getId()); + msInstanceInfo.put("name", msInstance.getName()); + return msInstanceInfo; + } + + private class BaseMsCreator { + + BaseMicroservice create(MicroserviceCreateRequest createRequest) { + BaseMicroservice microservice = new BaseMicroservice(); + microservice.setLocation(createRequest.getLocation()); + microservice.setName(createRequest.getName()); + microservice.setTag(createRequest.getTag()); + microservice.setServiceName(createRequest.getServiceName()); + microservice.setNamespace(createRequest.getNamespace()); + microservice.setStatus(BaseMsStatus.ACTIVE); + microservice.setType(createRequest.getType()); + microservice.setMetadata(getMetadataFields(createRequest)); + return microservice; + } + + private AuditFields getMetadataFields(MicroserviceCreateRequest request) { + AuditFields auditFields = AuditFields.builder().build(); + auditFields.setCreatedBy(request.getUser()); + auditFields.setCreatedOn(new Date()); + + if (request.getMetadata().containsKey("notes")) + auditFields.setNotes((String) request.getMetadata().get("notes")); + if (request.getMetadata().containsKey("labels")) +// auditFields.setLabels((List<String>) request.getMetadata().get("labels")); + auditFields.setLabels(request.getMetadata().get("labels")); + + return auditFields; + + } + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/ArtifactFileNameCreator.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/ArtifactFileNameCreator.java new file mode 100644 index 0000000..7713020 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/ArtifactFileNameCreator.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.BlueprintFileNameCreateException; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.springframework.stereotype.Component; + +/** + * A name creator for Deployment Artifact files. + */ +@Component +public class ArtifactFileNameCreator { + + private static final String FILE_FORMAT = ".yaml"; + + /** + * creates a file name + * @param msInstance + * @param version + * @return + */ + public String createFileName(MsInstance msInstance, int version) { + if(msInstance.getMsInfo() == null || !msInstance.getMsInfo().containsKey("tag")){ + throwException("MS-tag"); + } + if(msInstance.getActiveSpec() == null){ + throwException("active-spec"); + } + return msInstance.getMsInfo().get("tag") + "_" + + msInstance.getActiveSpec().getType().toString().toLowerCase() + "_" + + msInstance.getRelease() + "_" + + version + + FILE_FORMAT; + } + + private void throwException(String missingProperty) { + throw new BlueprintFileNameCreateException("Can not create bluerprint file name: " + + missingProperty + " is missing"); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactGateway.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactGateway.java new file mode 100644 index 0000000..6bf2c2a --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactGateway.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactSearch; + +import java.util.List; +import java.util.Optional; + + /** + * An interface to interact with DeploymentArtifact persistence + */ +public interface DeploymentArtifactGateway { + + List<DeploymentArtifact> findAll(); + + List<DeploymentArtifact> findByMsInstanceId(String id); + + Optional<DeploymentArtifact> findById(String id); + + void deleteById(String deploymentArtifactId); + + DeploymentArtifact save(DeploymentArtifact deploymentArtifact); + + List<DeploymentArtifact> findAll(DeploymentArtifactSearch search); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactGeneratorStrategy.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactGeneratorStrategy.java new file mode 100644 index 0000000..9bb0870 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactGeneratorStrategy.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.specification.Specification; + +import java.util.Map; + +/** + * provides abstraction to generate Deployment Artifacts + */ +public interface DeploymentArtifactGeneratorStrategy { + Map<String, Object> generateForRelease(Specification activeSpec, String release); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactService.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactService.java new file mode 100644 index 0000000..3e7f899 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactService.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactSearch; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.restapi.DeploymentArtifactPatchRequest; + +import java.util.List; + +/** + * An interface to access DeploymentArtifact Services + */ +public interface DeploymentArtifactService { + + DeploymentArtifact generateDeploymentArtifact(String msInstanceId, String user); + + List<DeploymentArtifact> getAllDeploymentArtifacts(); + + DeploymentArtifact findDeploymentArtifactById(String id); + + void updateDeploymentArtifact(String deploymentArtifactId, DeploymentArtifactPatchRequest deploymentArtifactPatchRequest, String user); + + List<DeploymentArtifact> findByMsInstanceId(String msInstanceId); + + void deleteDeploymentArtifact(String deploymentArtifactId); + + void updateMsInstanceRef(MsInstance msInstance); + + List<DeploymentArtifact> searchDeploymentArtifacts(DeploymentArtifactSearch search); +} + diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactServiceImpl.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactServiceImpl.java new file mode 100644 index 0000000..8b97bba --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactServiceImpl.java @@ -0,0 +1,205 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactSearch; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.MsInstanceInfo; +import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.DeploymentArtifactNotFound; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.DeploymentArtifactsRef; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.restapi.DeploymentArtifactPatchRequest; +import org.onap.dcaegen2.platform.mod.model.specification.Specification; +import org.onap.dcaegen2.platform.mod.web.service.microserviceinstance.MsInstanceService; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +/** + * DeploymentArtifact Service implementation + */ +@Service +@Slf4j +@Setter +public class DeploymentArtifactServiceImpl implements DeploymentArtifactService{ + + private static final String VERSION_KEY = "mostRecentVersion"; + + @Autowired + private MsInstanceService msInstanceService; + + @Autowired + private DeploymentArtifactGeneratorStrategy deploymentArtifactGeneratorStrategy; + + @Autowired + private DeploymentArtifactGateway deploymentArtifactGateway; + + @Autowired + private ArtifactFileNameCreator fileNameCreator; + + @Autowired + private DeploymentArtifactStatusChangeHandler statusChangeHandler; + + ///////////////FIND METHODS////////////////////////// + @Override + public List<DeploymentArtifact> getAllDeploymentArtifacts() { + return deploymentArtifactGateway.findAll(); + } + + @Override + public List<DeploymentArtifact> searchDeploymentArtifacts(DeploymentArtifactSearch search) { + return deploymentArtifactGateway.findAll(search); + } + + @Override + public DeploymentArtifact findDeploymentArtifactById(String id){ + return deploymentArtifactGateway.findById(id).orElseThrow( + () -> new DeploymentArtifactNotFound("Deployment Artifact with id " + id + " not found") + ); + } + + @Override + public List<DeploymentArtifact> findByMsInstanceId(String msInstanceId) { + return deploymentArtifactGateway.findByMsInstanceId(msInstanceId); + } + + @Override + @Transactional + public void deleteDeploymentArtifact(String deploymentArtifactId) { + DeploymentArtifact deploymentArtifact = findDeploymentArtifactById(deploymentArtifactId); + log.info("deleting {}", deploymentArtifact.getFileName()); + deploymentArtifactGateway.deleteById(deploymentArtifactId); + msInstanceService.removeDeploymentArtifactFromMsInstance(deploymentArtifact); + } + + @Override + @Transactional + public void updateMsInstanceRef(MsInstance msInstance) { + List<DeploymentArtifact> deploymentArtifacts = findByMsInstanceId(msInstance.getId()); + deploymentArtifacts.forEach((deploymentArtifact) -> { + deploymentArtifact.getMsInstanceInfo().setName(msInstance.getName()); + deploymentArtifact.getMsInstanceInfo().setRelease(msInstance.getRelease()); + deploymentArtifactGateway.save(deploymentArtifact); + }); + } + + ////////////////////////////////////////////////////// + + @Override + @Transactional + //only status update was implemented + public void updateDeploymentArtifact(String deploymentArtifactId, DeploymentArtifactPatchRequest deploymentArtifactPatchRequest, + String user) { + DeploymentArtifact deploymentArtifact = findDeploymentArtifactById(deploymentArtifactId); + updateStatus(deploymentArtifactPatchRequest, deploymentArtifact); + updateMetadata(user, deploymentArtifact); + log.info("Updating the artifact in database.."); + deploymentArtifactGateway.save(deploymentArtifact); + msInstanceService.updateStatusBasedOnDeploymentArtifactsStatuses(deploymentArtifact.getMsInstanceInfo().getId()); + } + + private void updateMetadata(String user, DeploymentArtifact deploymentArtifact) { + deploymentArtifact.getMetadata().put("updatedBy", user); + deploymentArtifact.getMetadata().put("updatedOn", new Date()); + } + + private void updateStatus(DeploymentArtifactPatchRequest deploymentArtifactPatchRequest, DeploymentArtifact deploymentArtifact) { + DeploymentArtifactStatus changeToStatus = deploymentArtifactPatchRequest.getStatus(); + if(changeToStatus != null){ + log.info("Sent request to deployment artifact status change handler: {}", changeToStatus); + statusChangeHandler.handleStatusChange(changeToStatus, deploymentArtifact); + } + } + + @Override + @Transactional + public DeploymentArtifact generateDeploymentArtifact(String msInstanceId, String user) { + MsInstance msInstance = msInstanceService.getMsInstanceById(msInstanceId); + + //Generate the Blueprint for the active specification for the instance + Map<String, Object> deploymentArtifact = deploymentArtifactGeneratorStrategy.generateForRelease(msInstance.getActiveSpec(), msInstance.getRelease()); + + DeploymentArtifact artifact = new DeploymentArtifact(); + artifact.setContent(String.valueOf(deploymentArtifact.get("content"))); + artifact.setVersion(updateLatestVersion(msInstance.getDeploymentArtifactsInfo())); + artifact.setStatus(DeploymentArtifactStatus.IN_DEV); + artifact.setMsInstanceInfo(createMsInstanceReferenceInfo(msInstance)); + artifact.setSpecificationInfo(createSpecificationReferenceInfo(msInstance.getActiveSpec())); + artifact.setMetadata(createMetadata(user)); + + artifact.setFileName(fileNameCreator.createFileName(msInstance, artifact.getVersion())); + + DeploymentArtifact savedDao = deploymentArtifactGateway.save(artifact); + artifact.setId(savedDao.getId()); + + msInstance.setDeploymentArtifactsInfo(updateMsDeploymentArtifactRef(msInstance.getDeploymentArtifactsInfo(), savedDao.getId())); + msInstanceService.updateMsInstance(msInstance); + + return artifact; + } + + private int updateLatestVersion(DeploymentArtifactsRef ref) { + if(ref == null) return 1; + else return ref.getMostRecentVersion() + 1; + } + + private DeploymentArtifactsRef updateMsDeploymentArtifactRef(DeploymentArtifactsRef ref, String deploymentArtifactId) { + if(ref == null){ + ref = new DeploymentArtifactsRef(); + ref.setMostRecentVersion(1); + List<String> deploymentArtifacts = new ArrayList<>(); + deploymentArtifacts.add(deploymentArtifactId); + ref.setDeploymentArtifacts(deploymentArtifacts); + } + else{ + ref.setMostRecentVersion(ref.getMostRecentVersion() + 1); + List<String> deploymentArtifactList = ref.getDeploymentArtifacts(); + deploymentArtifactList.add(deploymentArtifactId); + } + return ref; + } + + private Map<String, Object> createMetadata(String user) { + Map<String, Object> metadata = new HashMap<>(); + metadata.put("createdOn", new Date()); + metadata.put("createdBy", user); + return metadata; + } + + private Map<String, Object> createSpecificationReferenceInfo(Specification activeSpec) { + Map<String, Object> specInfo = new HashMap<>(); + specInfo.put("id", activeSpec.getId()); + return specInfo; + } + + private MsInstanceInfo createMsInstanceReferenceInfo(MsInstance msInstance) { + MsInstanceInfo msInstanceInfo = new MsInstanceInfo(); + msInstanceInfo.setId(msInstance.getId()); + msInstanceInfo.setName(msInstance.getName()); + msInstanceInfo.setRelease(msInstance.getRelease()); + return msInstanceInfo; + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandler.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandler.java new file mode 100644 index 0000000..48b18bf --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/deploymentartifact/DeploymentArtifactStatusChangeHandler.java @@ -0,0 +1,77 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.deploymentartifact; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus; +import org.onap.dcaegen2.platform.mod.model.exceptions.deploymentartifact.StatusChangeNotValidException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * A class responsible for handling status changes of Deployment Artifacts + */ +@Component +@Slf4j +public class DeploymentArtifactStatusChangeHandler { + + @Autowired + DeploymentArtifactService deploymentArtifactService; + + /** + * setter + * @param deploymentArtifactService + */ + public void setDeploymentArtifactService(DeploymentArtifactService deploymentArtifactService) { + this.deploymentArtifactService = deploymentArtifactService; + } + + /** + * handles status changes + * @param status + * @param deploymentArtifact + */ + public void handleStatusChange(DeploymentArtifactStatus status, DeploymentArtifact deploymentArtifact) { + String msInstanceId = deploymentArtifact.getMsInstanceInfo().getId(); + List<DeploymentArtifact> artifacts = deploymentArtifactService.findByMsInstanceId(msInstanceId); + if( status == DeploymentArtifactStatus.DEV_COMPLETE){ + for(DeploymentArtifact artifact : artifacts){ + if(artifact.getStatus() == DeploymentArtifactStatus.DEV_COMPLETE){ + log.error("Status change is not allowed."); + throw new StatusChangeNotValidException(createValidationErrorMessage(deploymentArtifact)); + } + } + } + deploymentArtifact.setStatus(status); + log.info("Deployment Artifact's status changed successfully."); + } + + private String createValidationErrorMessage(DeploymentArtifact artifact) { + return String.format( "%s (v%d) for %s - Status change not allowed." + + " Only 1 blueprint can be in the DEV_COMPLETE state. " + + "Change the current DEV_COMPLETE blueprint to NOT_NEEDED or IN_DEV before changing another" + + " to DEV_COMPLETE.", artifact.getMsInstanceInfo().getName(), + artifact.getVersion(), artifact.getMsInstanceInfo().getRelease()); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceGateway.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceGateway.java new file mode 100644 index 0000000..12a510a --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceGateway.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.microserviceinstance; + +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; + +import java.util.List; +import java.util.Optional; + +/** + * An interface to interact with MsInstance persistence + */ +public interface MsInstanceGateway { + + Optional<MsInstance> findByNameAndRelease(String name, String release); + + Optional<MsInstance> findById(String msInstanceId); + + List<MsInstance> findAll(); + + MsInstance save(MsInstance msInstance); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceService.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceService.java new file mode 100644 index 0000000..3c28f4d --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceService.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.microserviceinstance; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMicroservice; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceUpdateRequest; + +import java.util.List; + +/** + * An interface to access MsInstance Services + */ +public interface MsInstanceService { + + List<MsInstance> getAll(); + + MsInstance createMicroserviceInstance(String msName, MsInstanceRequest request); + + MsInstance getMsInstanceById(String id); + + void updateMsInstance(MsInstance msInstance); + + void updateStatusBasedOnDeploymentArtifactsStatuses(String msInstanceId); + + void removeDeploymentArtifactFromMsInstance(DeploymentArtifact deploymentArtifact); + + void updateMicroserviceReference(BaseMicroservice msToBeUpdated); + + MsInstance updateMsInstance(MsInstanceUpdateRequest updateRequest, String msInstanceId); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceServiceImpl.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceServiceImpl.java new file mode 100644 index 0000000..e4d5694 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceServiceImpl.java @@ -0,0 +1,213 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.microserviceinstance; + +import org.onap.dcaegen2.platform.mod.model.basemicroservice.BaseMicroservice; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.exceptions.msinstance.MsInstanceAlreadyExistsException; +import org.onap.dcaegen2.platform.mod.model.exceptions.msinstance.MsInstanceNotFoundException; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstanceStatus; +import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceUpdateRequest; +import org.onap.dcaegen2.platform.mod.web.service.basemicroservice.MsService; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactService; +import org.onap.dcaegen2.platform.mod.web.service.specification.SpecificationService; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * MsInstance Service implementation + */ +@Service +@Setter +@Slf4j +public class MsInstanceServiceImpl implements MsInstanceService { + + @Autowired + private MsInstanceGateway msInstanceRepository; + + @Autowired + private MsService msService; + + @Autowired + private MsInstanceStatusChangeHandler msInstanceStatusChangeHandler; + + @Autowired + private SpecificationService specificationService; + + @Autowired + private DeploymentArtifactService deploymentArtifactService; + + @Override + public List<MsInstance> getAll() { + return msInstanceRepository.findAll(); + } + + @Override + @Transactional + public MsInstance createMicroserviceInstance(String msName, MsInstanceRequest request) { + BaseMicroservice microservice = msService.getMicroserviceByName(msName); + checkIftheCombinationOfNameAndReleaseIsUnique(request.getName(), request.getRelease()); + MsInstance msInstance = new MsInstanceCreator(request, microservice).create(); + MsInstance savedMsInstance = msInstanceRepository.save(msInstance); + msService.saveMsInstanceReferenceToMs(microservice, savedMsInstance); + return savedMsInstance; + } + + private void checkIftheCombinationOfNameAndReleaseIsUnique(String name, String release) { + if (msInstanceRepository.findByNameAndRelease(name, release).isPresent()) + throw new MsInstanceAlreadyExistsException(); + } + + @Override + public MsInstance getMsInstanceById(String id) { + return msInstanceRepository.findById(id).orElseThrow(() -> + new MsInstanceNotFoundException(String.format("Ms Instance with id %s not found", id))); + } + + @Override + public void updateMsInstance(MsInstance msInstance) { + log.info("Saving the msInstance {} to database..", msInstance); + if(msInstance != null) msInstanceRepository.save(msInstance); + } + + @Override + public void updateStatusBasedOnDeploymentArtifactsStatuses(String msInstanceId) { + MsInstance msInstance = getMsInstanceById(msInstanceId); + msInstanceStatusChangeHandler.updateStatusBasedOnDeploymentArtifactsStatuses(msInstance); + updateMsInstance(msInstance); + } + + @Override + @Transactional + public void removeDeploymentArtifactFromMsInstance(DeploymentArtifact deploymentArtifact) { + MsInstance msInstance = getMsInstanceById(deploymentArtifact.getMsInstanceInfo().getId()); + removeDeploymentArtifactReferenceFromMsInstance(msInstance, deploymentArtifact.getId()); + msInstanceStatusChangeHandler.updateStatusBasedOnDeploymentArtifactsStatuses(msInstance); + updateMsInstance(msInstance); + } + + @Override + //TODO: update msInstanceReference in specification and deployment artifact + public void updateMicroserviceReference(BaseMicroservice microservice) { + List<Map<String, String>> msInstanceRefs = microservice.getMsInstances(); + for(Map<String, String> ref : msInstanceRefs){ + MsInstance msInstance = getMsInstanceById(ref.get("id")); + msInstance.setName(microservice.getName()); + msInstance.getMsInfo().put("name", microservice.getName()); + cascadeUpdates(msInstance); + msInstanceRepository.save(msInstance); + } + } + + @Override + @Transactional + public MsInstance updateMsInstance(MsInstanceUpdateRequest updateRequest, String msInstanceId) { + MsInstance msInstance = getMsInstanceById(msInstanceId); + updateRelease(updateRequest, msInstance); + updateVersion(updateRequest, msInstance); + updateMetadata(updateRequest, msInstance); + cascadeUpdates(msInstance); + return msInstanceRepository.save(msInstance); + } + + private void cascadeUpdates(MsInstance msInstance) { + specificationService.updateMsInstanceRef(msInstance); + deploymentArtifactService.updateMsInstanceRef(msInstance); + msService.updateMsInstanceRef(msInstance); + } + + private void updateMetadata(MsInstanceUpdateRequest updateRequest, MsInstance msInstance) { + if(updateRequest.getMetadata() != null){ + msInstance.getMetadata().putAll(updateRequest.getMetadata()); + } + + msInstance.getMetadata().put("updatedOn", new Date()); + msInstance.getMetadata().put("updatedBy", updateRequest.getUser()); + } + + private void updateVersion(MsInstanceUpdateRequest updateRequest, MsInstance msInstance) { + if(updateRequest.getVersion() != null){ + msInstance.setVersion(updateRequest.getVersion()); + } + } + + private void updateRelease(MsInstanceUpdateRequest updateRequest, MsInstance msInstance) { + if(updateRequest.getRelease() != null) { + if(!updateRequest.getRelease().equals(msInstance.getRelease())) + checkIftheCombinationOfNameAndReleaseIsUnique(msInstance.getName(), updateRequest.getRelease()); + msInstance.setRelease(updateRequest.getRelease()); + } + } + + private void removeDeploymentArtifactReferenceFromMsInstance(MsInstance msInstance, String deploymentArtifactId) { + if(msInstance.getDeploymentArtifactsInfo() != null){ + List<String> refIds = msInstance.getDeploymentArtifactsInfo().getDeploymentArtifacts(); + refIds.remove(deploymentArtifactId); + } + } + + private class MsInstanceCreator { + private MsInstanceRequest request; + private BaseMicroservice microserviceDAO; + + MsInstanceCreator(MsInstanceRequest request, BaseMicroservice microserviceDAO) { + this.request = request; + this.microserviceDAO = microserviceDAO; + } + + MsInstance create() { + //prepare MsInstance from the request + return MsInstance.builder() + .name(request.getName()) + .release(request.getRelease()) + .status(MsInstanceStatus.NEW) + .version(request.getVersion()) + .msInfo(getMsReference(microserviceDAO)) + .metadata(getMetadata(request)) + .build(); + } + + private Map<String, Object> getMsReference(BaseMicroservice microserviceDAO) { + Map<String,Object> msInfo = new HashMap<>(); + msInfo.put("id", microserviceDAO.getId()); + msInfo.put("name", microserviceDAO.getName()); + msInfo.put("tag", microserviceDAO.getTag()); + return msInfo; + } + + private Map<String, Object> getMetadata(MsInstanceRequest request) { + Map<String, Object> metadata = request.getMetadata(); + metadata.put("createdBy", request.getUser()); + metadata.put("createdOn", new Date()); + return metadata; + } + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceStatusChangeHandler.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceStatusChangeHandler.java new file mode 100644 index 0000000..bc26fab --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/microserviceinstance/MsInstanceStatusChangeHandler.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.microserviceinstance; + +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact; +import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstanceStatus; +import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * A class responsible for handling status changes of Ms Instances + */ +@Component +@Slf4j +public class MsInstanceStatusChangeHandler { + + @Autowired + private MsInstanceService msInstanceService; + + @Autowired + private DeploymentArtifactService deploymentArtifactService; + + public void setMsInstanceService(MsInstanceService msInstanceService) { + this.msInstanceService = msInstanceService; + } + + public void setDeploymentArtifactService(DeploymentArtifactService deploymentArtifactService) { + this.deploymentArtifactService = deploymentArtifactService; + } + + public void updateStatusBasedOnDeploymentArtifactsStatuses(MsInstance msInstance) { + log.info("Checking if any Status change required for msInstance {}...", msInstance); + List<DeploymentArtifact> artifacts = deploymentArtifactService.findByMsInstanceId(msInstance.getId()); + MsInstanceStatus newStatus = getValidStatusBasedOnArtifacts(artifacts); + msInstance.setStatus(newStatus); + log.info("Changed Status to {}", newStatus); + } + + private MsInstanceStatus getValidStatusBasedOnArtifacts(List<DeploymentArtifact> artifacts) { + if(atLeastOneArtifactHasDevCompleteStatus(artifacts)){ + return MsInstanceStatus.DEV_COMPLETE; + } + return MsInstanceStatus.IN_DEV; + } + + private boolean atLeastOneArtifactHasDevCompleteStatus(List<DeploymentArtifact> artifacts) { + return artifacts + .stream() + .anyMatch(artifact -> artifact.getStatus() == DeploymentArtifactStatus.DEV_COMPLETE); + } +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationGateway.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationGateway.java new file mode 100644 index 0000000..5fcfbb1 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationGateway.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.specification; + +import org.onap.dcaegen2.platform.mod.model.specification.Specification; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * An interface to interact with Specification persistence + */ +@Repository +public interface SpecificationGateway{ + + List<Specification> getSpecificationByMsInstanceId(String id); + + Specification save(Specification newSpec); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationService.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationService.java new file mode 100644 index 0000000..33724ac --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationService.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.specification; + +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.restapi.SpecificationRequest; +import org.onap.dcaegen2.platform.mod.model.specification.Specification; + +import java.util.List; + +/** + * An interface to access Specification Services + */ +public interface SpecificationService { + + List<Specification> getAllSpecsByMsInstanceId(String id); + + Specification createSpecification(String msInstanceId, SpecificationRequest request); + + void updateMsInstanceRef(MsInstance msInstance); +} + diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationServiceImpl.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationServiceImpl.java new file mode 100644 index 0000000..7869801 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationServiceImpl.java @@ -0,0 +1,138 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.specification; + +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance; +import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstanceStatus; +import org.onap.dcaegen2.platform.mod.model.restapi.SpecificationRequest; +import org.onap.dcaegen2.platform.mod.model.specification.Specification; +import org.onap.dcaegen2.platform.mod.model.specification.SpecificationStatus; +import org.onap.dcaegen2.platform.mod.web.service.microserviceinstance.MsInstanceService; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Specification Service implementation + */ +@Service +@Setter +public class SpecificationServiceImpl implements SpecificationService { + + @Autowired + private SpecificationGateway specificationGateway; + + @Autowired + private MsInstanceService msInstanceService; + + @Autowired + private SpecificationValidatorService specificationValidatorService; + + /** + * Lists all Ms Instances + * @param id + * @return + */ + @Override + public List<Specification> getAllSpecsByMsInstanceId(String id) { + return specificationGateway.getSpecificationByMsInstanceId(id); + } + + /** + * creates a Specification + * @param msInstanceId + * @param request + * @return + */ + @Override + @Transactional + public Specification createSpecification(String msInstanceId, SpecificationRequest request) { + MsInstance msInstance = msInstanceService.getMsInstanceById(msInstanceId); + specificationValidatorService.validateSpecForRelease(request, msInstance.getRelease()); + Specification newSpec = createSpecification(request, msInstance); + makePreviousSpecInactive(msInstance); + Specification savedSpec = specificationGateway.save(newSpec); + updateMsInstance(msInstance, savedSpec); + return savedSpec; + } + + private Specification createSpecification(SpecificationRequest request, MsInstance msInstance) { + return Specification.builder() + .status(SpecificationStatus.ACTIVE) + .specContent(request.getSpecContent()) + .policyJson(request.getPolicyJson()) + .type(request.getType()) + .metadata(getMetadata(request)) + .msInstanceInfo(buildMsInstanceInfo(msInstance)) + .build(); + } + + private void updateMsInstance(MsInstance msInstance, Specification savedSpecification) { + msInstance.setActiveSpec(savedSpecification); + msInstance.setStatus(MsInstanceStatus.IN_DEV); + msInstanceService.updateMsInstance(msInstance); + } + + private void makePreviousSpecInactive(MsInstance msInstance) { + if (msInstance.getActiveSpec() != null) { + msInstance.getActiveSpec().setStatus(SpecificationStatus.INACTIVE); + specificationGateway.save(msInstance.getActiveSpec()); + } + } + + private Map<String, Object> getMetadata(SpecificationRequest request) { + Map<String, Object> metadata = request.getMetadata(); + metadata.put("createdBy", request.getUser()); + metadata.put("createdOn", new Date()); + return metadata; + } + + private Map<String, Object> buildMsInstanceInfo(MsInstance msInstance) { + Map<String, Object> msInstanceInfo = new HashMap<>(); + msInstanceInfo.put("id", msInstance.getId()); + msInstanceInfo.put("name", msInstance.getName()); + msInstanceInfo.put("release", msInstance.getRelease()); + return msInstanceInfo; + } + + /** + * Updates a MsInstance reference in a Specification record + * @param msInstance + */ + @Override + @Transactional + public void updateMsInstanceRef(MsInstance msInstance) { + List<Specification> specifications = getAllSpecsByMsInstanceId(msInstance.getId()); + specifications.forEach((specification) ->{ + specification.getMsInstanceInfo().put("name", msInstance.getName()); + specification.getMsInstanceInfo().put("release", msInstance.getRelease()); + specificationGateway.save(specification); + }); + } + + +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationValidationStratergy.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationValidationStratergy.java new file mode 100644 index 0000000..58eff19 --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationValidationStratergy.java @@ -0,0 +1,30 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.specification; + +import org.onap.dcaegen2.platform.mod.model.restapi.SpecificationRequest; + +/** + * Abstraction for Specification Validation. + */ +public interface SpecificationValidationStratergy { + public void validate(SpecificationRequest specificationRequest, String release); +} diff --git a/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationValidatorService.java b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationValidatorService.java new file mode 100644 index 0000000..6d10aee --- /dev/null +++ b/mod2/catalog-service/src/main/java/org/onap/dcaegen2/platform/mod/web/service/specification/SpecificationValidatorService.java @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service.specification; + +import org.onap.dcaegen2.platform.mod.model.restapi.SpecificationRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * A service to validate specification + */ +@Service +public class SpecificationValidatorService { + + @Autowired + SpecificationValidationStratergy specValidator; + + public void validateSpecForRelease(SpecificationRequest specificationRequest, String release) { + specValidator.validate(specificationRequest, release); + } +} + + + + + + + + + + + + + + + + + + + + + + diff --git a/mod2/catalog-service/src/main/resources/application.properties b/mod2/catalog-service/src/main/resources/application.properties new file mode 100644 index 0000000..1f20c6a --- /dev/null +++ b/mod2/catalog-service/src/main/resources/application.properties @@ -0,0 +1,24 @@ +# +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +# + +#add connection to mongo db once its up and running +spring.data.mongodb.host=mongo_db +spring.data.mongodb.port=27017 +spring.data.mongodb.database=dcae_mod
\ No newline at end of file |