diff options
Diffstat (limited to 'vnfm-simulator/vnfm-service/src')
16 files changed, 1109 insertions, 0 deletions
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/config/SvnfmApplication.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/config/SvnfmApplication.java new file mode 100644 index 0000000000..84b45d0bac --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/config/SvnfmApplication.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author ronan.kenny@est.tech + */ +@SpringBootApplication(scanBasePackages = {"org.onap"}) +@EnableJpaRepositories("org.onap.svnfm.simulator") +@EntityScan("org.onap.svnfm.simulator.model") +@EnableCaching +public class SvnfmApplication { + public static void main(final String[] args) { + SpringApplication.run(SvnfmApplication.class, args); + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/constants/Constant.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/constants/Constant.java new file mode 100644 index 0000000000..bd380903d5 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/constants/Constant.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.constants; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author ronan.kenny@est.tech + */ +public class Constant { + + public static final String VNF_PROVIDER = "XYZ"; + public static final String VNF_PROVIDER_NAME = "SGSN-MME"; + public static final String VNF_SOFTWARE_VERSION = "1.24"; + public static final String VNFD_VERSION = "onapmme01_cxp9025898_4r85d01"; + public static final String VNF_NOT_INSTANTIATED = "NOT_INSTANTIATED"; +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java new file mode 100644 index 0000000000..11099a24fc --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java @@ -0,0 +1,142 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.controller; + +import java.util.UUID; +import javax.ws.rs.core.MediaType; +import org.onap.svnfm.simulator.repository.VnfmCacheRepository; +import org.onap.svnfm.simulator.services.SvnfmService; +import org.onap.vnfm.v1.model.CreateVnfRequest; +import org.onap.vnfm.v1.model.InlineResponse201; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +@RestController +@RequestMapping("/svnfm") +public class SvnfmController { + + @Autowired + private SvnfmService svnfmService; + + @Autowired + private VnfmCacheRepository vnfmCacheRepository; + + private static final Logger LOGGER = LoggerFactory.getLogger(SvnfmController.class); + + /** + * + * @param createVNFRequest + * @return + */ + @RequestMapping(method = RequestMethod.POST, value = "/vnf_instances") + public ResponseEntity<InlineResponse201> createVnf(@RequestBody final CreateVnfRequest createVNFRequest) { + LOGGER.info("Start createVnf------"); + final HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", MediaType.APPLICATION_JSON); + return new ResponseEntity<>(vnfmCacheRepository.createVnf(createVNFRequest), headers, HttpStatus.CREATED); + } + + /** + * + * @param vnfId + * @return vnfm cache repository + */ + @RequestMapping(method = RequestMethod.GET, value = "/vnf_instances/{vnfInstanceId}", + produces = MediaType.APPLICATION_JSON) + @ResponseStatus(code = HttpStatus.OK) + public InlineResponse201 getVnf(@PathVariable("vnfInstanceId") final String vnfId) { + LOGGER.info("Start getVnf------"); + return vnfmCacheRepository.getVnf(vnfId); + } + + /** + * + * @param vnfId + * @return response entity + * @throws InterruptedException + */ + @RequestMapping(method = RequestMethod.POST, value = "/vnf_instances/{vnfInstanceId}/instantiate") + public ResponseEntity<Object> instantiateVnf(@PathVariable("vnfInstanceId") final String vnfId) + throws InterruptedException { + LOGGER.info("Start instantiateVNFRequest"); + final String instantiateJobId = UUID.randomUUID().toString(); + final HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", MediaType.APPLICATION_JSON); + headers.add("Location", instantiateJobId); + return new ResponseEntity<>(svnfmService.instatiateVnf(vnfId, instantiateJobId), headers, HttpStatus.ACCEPTED); + } + + /** + * + * @param jobId + * @return response entity + * @throws InterruptedException + */ + public ResponseEntity<Object> getJobStatus(@PathVariable("jobId") final String jobId) throws InterruptedException { + LOGGER.info("Start getJobStatus"); + final HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", MediaType.APPLICATION_JSON); + return new ResponseEntity<>(svnfmService.getJobStatus(jobId), headers, HttpStatus.ACCEPTED); + } + + /** + * + * @param vnfId + * @return delete VNF + */ + @RequestMapping(method = RequestMethod.DELETE, value = "/vnf_instances/{vnfInstanceId}", + produces = MediaType.APPLICATION_JSON) + @ResponseStatus(code = HttpStatus.OK) + public InlineResponse201 deleteVnf(@PathVariable("vnfInstanceId") final String vnfId) { + LOGGER.info("Start deleting Vnf------"); + return vnfmCacheRepository.deleteVnf(vnfId); + } + + /** + * + * @param vnfId + * @return response entity + * @throws InterruptedException + */ + @RequestMapping(method = RequestMethod.POST, value = "/vnf_instances/{vnfInstanceId}/terminate") + public ResponseEntity<Object> terminateVnf(@PathVariable("vnfInstanceId") final String vnfId) + throws InterruptedException { + LOGGER.info("Start terminateVNFRequest"); + final HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", MediaType.APPLICATION_JSON); + return new ResponseEntity<>(svnfmService.terminateVnf(vnfId), headers, HttpStatus.ACCEPTED); + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/exception/GlobalExceptionHandler.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000000..1ea92b39ad --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/exception/GlobalExceptionHandler.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.exception; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author ronan.kenny@est.tech + */ +@ControllerAdvice +public class GlobalExceptionHandler { + + private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); + + @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) + @ExceptionHandler(HttpMediaTypeNotSupportedException.class) + public void handleConflict() { + final String error = "Media type Not Supported"; + logger.error(error); + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/model/VnfInstance.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/model/VnfInstance.java new file mode 100644 index 0000000000..6af860c8f8 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/model/VnfInstance.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +@Entity +@Table(name = "VNF_INSTANCE") +public class VnfInstance { + @Id + @Column(name = "id", nullable = false) + private String id; + private String vnfInstanceName; + private String vnfInstanceDescription; + private String vnfdId; + private String vnfProvider; + private String vnfProductName; + private String vnfSoftwareVersion; + private String vnfdVersion; + private String vnfPkgId; + private String vnfConfigurableProperties; + private String vimConnectionInfo; + private String vnfInstantiationState; + private String instantiatedVnfInfo; + private String metadata; + private String extensions; + private String links; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getVnfInstanceName() { + return vnfInstanceName; + } + + public void setVnfInstanceName(final String vnfInstanceName) { + this.vnfInstanceName = vnfInstanceName; + } + + public String getVnfInstanceDescription() { + return vnfInstanceDescription; + } + + public void setVnfInstanceDescription(final String vnfInstanceDescription) { + this.vnfInstanceDescription = vnfInstanceDescription; + } + + public String getVnfdId() { + return vnfdId; + } + + public void setVnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + } + + public String getVnfProvider() { + return vnfProvider; + } + + public void setVnfProvider(final String vnfProvider) { + this.vnfProvider = vnfProvider; + } + + public String getVnfProductName() { + return vnfProductName; + } + + public void setVnfProductName(final String vnfProductName) { + this.vnfProductName = vnfProductName; + } + + public String getVnfSoftwareVersion() { + return vnfSoftwareVersion; + } + + public void setVnfSoftwareVersion(final String vnfSoftwareVersion) { + this.vnfSoftwareVersion = vnfSoftwareVersion; + } + + public String getVnfdVersion() { + return vnfdVersion; + } + + public void setVnfdVersion(final String vnfdVersion) { + this.vnfdVersion = vnfdVersion; + } + + public String getVnfPkgId() { + return vnfPkgId; + } + + public void setVnfPkgId(final String vnfPkgId) { + this.vnfPkgId = vnfPkgId; + } + + public String getVnfConfigurableProperties() { + return vnfConfigurableProperties; + } + + public void setVnfConfigurableProperties(final String vnfConfigurableProperties) { + this.vnfConfigurableProperties = vnfConfigurableProperties; + } + + public String getVimConnectionInfo() { + return vimConnectionInfo; + } + + public void setVimConnectionInfo(final String vimConnectionInfo) { + this.vimConnectionInfo = vimConnectionInfo; + } + + public String getInstantiationState() { + return vnfInstantiationState; + } + + public void setVnfInstantiationState(final String vnfInstantiationState) { + this.vnfInstantiationState = vnfInstantiationState; + } + + public String getVnfInstantiationState() { + return instantiatedVnfInfo; + } + + public void setInstantiatedVnfInfo(final String instantiatedVnfInfo) { + this.instantiatedVnfInfo = instantiatedVnfInfo; + } + + public String getMetadata() { + return metadata; + } + + public void setMetadata(final String metadata) { + this.metadata = metadata; + } + + public String getExtensions() { + return extensions; + } + + public void setExtensions(final String extensions) { + this.extensions = extensions; + } + + public String getLinks() { + return links; + } + + public void setLinks(final String links) { + this.links = links; + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/model/VnfJob.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/model/VnfJob.java new file mode 100644 index 0000000000..575223c700 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/model/VnfJob.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.svnfm.simulator.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +@Entity +@Table(name = "VNF_JOB") +public class VnfJob { + @Id + @Column(name = "jobId", nullable = false) + private String jobId; + private String vnfInstanceId; + private String vnfId; + private String status; + + public String getJobId() { + return jobId; + } + + public void setJobId(final String jobId) { + this.jobId = jobId; + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(final String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public String getVnfId() { + return vnfId; + } + + public void setVnfId(final String vnfId) { + this.vnfId = vnfId; + } + + public String getStatus() { + return status; + } + + public void setStatus(final String status) { + this.status = status; + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfInstantiationNotification.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfInstantiationNotification.java new file mode 100644 index 0000000000..3bf3d602c5 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfInstantiationNotification.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.notifications; + +import org.onap.svnfm.simulator.services.SvnfmService; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +public class VnfInstantiationNotification implements Runnable { + + SvnfmService svnfmService = new SvnfmService(); + + @Override + public void run() { + try { + Thread.sleep(10000); + } catch (final InterruptedException e) { + e.printStackTrace(); + } + System.out.println("Instantiation process finished"); + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfmAdapterCreationNotification.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfmAdapterCreationNotification.java new file mode 100644 index 0000000000..61d6f7e6c2 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfmAdapterCreationNotification.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.notifications; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +public class VnfmAdapterCreationNotification implements Runnable { + + @Override + public void run() { + try { + Thread.sleep(10000); + } catch (final InterruptedException e) { + e.printStackTrace(); + } + System.out.println("Call to VNFM Adapter-Create"); + } + +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfmAdapterDeletionNotification.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfmAdapterDeletionNotification.java new file mode 100644 index 0000000000..0ad7365d30 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/notifications/VnfmAdapterDeletionNotification.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.notifications; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +public class VnfmAdapterDeletionNotification implements Runnable { + + @Override + public void run() { + try { + Thread.sleep(10000); + } catch (final InterruptedException e) { + e.printStackTrace(); + } + System.out.println("Call to VNFM Adapter-Delete"); + } + +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfJobRepository.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfJobRepository.java new file mode 100644 index 0000000000..b3b39bfdf1 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfJobRepository.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.repository; + +import org.onap.svnfm.simulator.model.VnfJob; +import org.springframework.data.repository.CrudRepository; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +public interface VnfJobRepository extends CrudRepository<VnfJob, String> { + +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmCacheRepository.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmCacheRepository.java new file mode 100644 index 0000000000..e41cbe1e3a --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmCacheRepository.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.repository; + +import org.onap.svnfm.simulator.services.SvnfmService; +import org.onap.vnfm.v1.model.CreateVnfRequest; +import org.onap.vnfm.v1.model.InlineResponse201; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Repository; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +@Repository +public class VnfmCacheRepository { + + @Autowired + private SvnfmService svnfmService; + + @Cacheable(value = "inlineResponse201", key = "#createVnfRequest.vnfdId") + public InlineResponse201 createVnf(final CreateVnfRequest createVnfRequest) { + return svnfmService.createVnf(createVnfRequest); + } + + @Cacheable(value = "inlineResponse201", key = "#id") + public InlineResponse201 getVnf(final String id) { + return svnfmService.getVnf(id); + } + + /** + * @param vnfId + * @return + */ + public InlineResponse201 deleteVnf(String vnfId) { + // TODO + return null; + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmRepository.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmRepository.java new file mode 100644 index 0000000000..f28b54a137 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmRepository.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.repository; + +import java.util.Optional; +import org.onap.svnfm.simulator.model.VnfInstance; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +public interface VnfmRepository extends CrudRepository<VnfInstance, String> { + public Optional<VnfInstance> findById(@Param("id") String id); +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java new file mode 100644 index 0000000000..f7f4eaa4a2 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java @@ -0,0 +1,168 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.services; + +import java.lang.reflect.InvocationTargetException; +import java.util.Optional; +import org.onap.svnfm.simulator.model.VnfInstance; +import org.onap.svnfm.simulator.model.VnfJob; +import org.onap.svnfm.simulator.notifications.VnfInstantiationNotification; +import org.onap.svnfm.simulator.notifications.VnfmAdapterCreationNotification; +import org.onap.svnfm.simulator.repository.VnfJobRepository; +import org.onap.svnfm.simulator.repository.VnfmRepository; +import org.onap.vnfm.v1.model.CreateVnfRequest; +import org.onap.vnfm.v1.model.InlineResponse201; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +@Service +public class SvnfmService { + + @Autowired + VnfmRepository vnfmRepository; + + @Autowired + VnfJobRepository vnfJobRepository; + + @Autowired + private VnfmHelper vnfmHelper; + + private static final Logger LOGGER = LoggerFactory.getLogger(SvnfmService.class); + + /** + * + * @param createVNFRequest + * @return inlineResponse201 + */ + public InlineResponse201 createVnf(final CreateVnfRequest createVNFRequest) { + InlineResponse201 inlineResponse201 = null; + try { + final VnfInstance vnfInstance = vnfmHelper.createVnfInstance(createVNFRequest); + vnfmRepository.save(vnfInstance); + final Thread creationNotification = new Thread(new VnfmAdapterCreationNotification()); + creationNotification.start(); + inlineResponse201 = vnfmHelper.getInlineResponse201(vnfInstance); + LOGGER.debug("Response from Create VNF", inlineResponse201); + } catch (IllegalAccessException | InvocationTargetException e) { + LOGGER.error("Failed in Create Vnf", e); + } + return inlineResponse201; + } + + /** + * + * @param vnfId + * @param instantiateJobId + * @throws InterruptedException + */ + public Object instatiateVnf(final String vnfId, final String instantiateJobId) throws InterruptedException { + final VnfJob vnfJob = buildVnfInstantiation(vnfId, instantiateJobId); + vnfJobRepository.save(vnfJob); + getJobStatus(vnfJob.getJobId()); + return null; + } + + /** + * + * @param vnfId + * @param instantiateJobId + */ + public VnfJob buildVnfInstantiation(final String vnfId, final String instantiateJobId) { + final VnfJob vnfJob = new VnfJob(); + final Optional<VnfInstance> vnfInstance = vnfmRepository.findById(vnfId); + + if (vnfInstance.isPresent()) { + vnfJob.setJobId(instantiateJobId); + for (final VnfInstance instance : vnfmRepository.findAll()) { + if (instance.getId().equals(vnfId)) { + vnfJob.setVnfInstanceId(instance.getVnfInstanceDescription()); + } + } + vnfJob.setVnfId(vnfId); + vnfJob.setStatus("STARTING"); + } + return vnfJob; + } + + /** + * + * @param jobId + * @throws InterruptedException + */ + public Object getJobStatus(final String jobId) throws InterruptedException { + LOGGER.info("Getting job status with id: " + jobId); + for (int i = 0; i < 5; i++) { + LOGGER.info("Instantiation status: RUNNING"); + Thread.sleep(5000); + for (final VnfJob job : vnfJobRepository.findAll()) { + if (job.getJobId().equals(jobId)) { + job.setStatus("RUNNING"); + vnfJobRepository.save(job); + } + } + } + final Thread instantiationNotification = new Thread(new VnfInstantiationNotification()); + instantiationNotification.start(); + for (final VnfJob job : vnfJobRepository.findAll()) { + if (job.getJobId().equals(jobId)) { + job.setStatus("COMPLETE"); + vnfJobRepository.save(job); + } + } + return null; + } + + /** + * + * @param vnfId + * @return inlineResponse201 + */ + public InlineResponse201 getVnf(final String vnfId) { + InlineResponse201 inlineResponse201 = null; + + final Optional<VnfInstance> vnfInstance = vnfmRepository.findById(vnfId); + try { + if (vnfInstance.isPresent()) { + inlineResponse201 = vnfmHelper.getInlineResponse201(vnfInstance.get()); + LOGGER.debug("Response from get VNF", inlineResponse201); + } + } catch (IllegalAccessException | InvocationTargetException e) { + LOGGER.error("Failed in get Vnf", e); + } + return inlineResponse201; + } + + /** + * @param vnfId + * @return + */ + public Object terminateVnf(String vnfId) { + // TODO + return null; + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/VnfmHelper.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/VnfmHelper.java new file mode 100644 index 0000000000..f35cbf2f49 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/VnfmHelper.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.services; + +import java.lang.reflect.InvocationTargetException; +import org.apache.commons.beanutils.BeanUtils; +import org.onap.svnfm.simulator.constants.Constant; +import org.onap.svnfm.simulator.model.VnfInstance; +import org.onap.vnfm.v1.model.CreateVnfRequest; +import org.onap.vnfm.v1.model.InlineResponse201; +import org.onap.vnfm.v1.model.InlineResponse201.InstantiationStateEnum; +import org.springframework.stereotype.Component; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * @author Ronan Kenny (ronan.kenny@est.tech) + */ +@Component +public class VnfmHelper { + + /** + * + * @param createVNFRequest + * @return vnfInstance + */ + public VnfInstance createVnfInstance(final CreateVnfRequest createVNFRequest) { + final VnfInstance vnfInstance = new VnfInstance(); + final String vnfId = createVNFRequest.getVnfdId(); + vnfInstance.setId(vnfId); + vnfInstance.setVnfInstanceName(createVNFRequest.getVnfInstanceName()); + vnfInstance.setVnfInstanceDescription(createVNFRequest.getVnfInstanceDescription()); + vnfInstance.setVnfdId(createVNFRequest.getVnfdId()); + vnfInstance.setVnfProvider(Constant.VNF_PROVIDER); + vnfInstance.setVnfProductName(Constant.VNF_PROVIDER_NAME); + return vnfInstance; + } + + /** + * + * @param vnfInstance + * @return inlineResponse201 + * @throws IllegalAccessException + * @throws InvocationTargetException + */ + public InlineResponse201 getInlineResponse201(final VnfInstance vnfInstance) + throws IllegalAccessException, InvocationTargetException { + final InlineResponse201 inlineResponse201 = new InlineResponse201(); + BeanUtils.copyProperties(inlineResponse201, vnfInstance); + inlineResponse201.setVnfdVersion(Constant.VNFD_VERSION); + inlineResponse201.setVnfSoftwareVersion(Constant.VNF_SOFTWARE_VERSION); + inlineResponse201.setInstantiationState(InstantiationStateEnum.NOT_INSTANTIATED); + return inlineResponse201; + } +} diff --git a/vnfm-simulator/vnfm-service/src/main/resources/application.properties b/vnfm-simulator/vnfm-service/src/main/resources/application.properties new file mode 100644 index 0000000000..c5b36d77f4 --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/main/resources/application.properties @@ -0,0 +1,13 @@ +# Enabling H2 Console +spring.h2.console.enabled=true +spring.h2.console.path=/console +spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE +spring.datasource.username=admin +spring.datasource.password=admin +spring.datasource.driverClassName=org.h2.Driver +spring.jpa.hibernate.ddl-auto = update +spring.jpa.show-sql=true +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE + +server.port=9081
\ No newline at end of file diff --git a/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/controllers/TestSvnfmController.java b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/controllers/TestSvnfmController.java new file mode 100644 index 0000000000..f338b5828e --- /dev/null +++ b/vnfm-simulator/vnfm-service/src/test/java/org/onap/svnfm/simulator/controllers/TestSvnfmController.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.svnfm.simulator.controllers; + +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.svnfm.simulator.controller.SvnfmController; +import org.onap.svnfm.simulator.repository.VnfmCacheRepository; +import org.onap.svnfm.simulator.services.SvnfmService; +import org.onap.vnfm.v1.model.CreateVnfRequest; +import org.onap.vnfm.v1.model.InlineResponse201; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class TestSvnfmController { + + @InjectMocks + private SvnfmController svnfmController; + + private MockMvc mockMvc; + + @Mock + private SvnfmService svnfmService; + + @Mock + private VnfmCacheRepository vnfmCacheRepository; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + this.mockMvc = MockMvcBuilders.standaloneSetup(svnfmController).build(); + } + + @Test + public void createVnfInstanceTest() throws Exception { + final CreateVnfRequest createVnfRequest = new CreateVnfRequest(); + + createVnfRequest.setVnfdId("123456798"); + createVnfRequest.setVnfInstanceName("createVnfInstanceTest"); + createVnfRequest.setVnfInstanceDescription("createVnfInstanceTest"); + + when(vnfmCacheRepository.createVnf(createVnfRequest)).thenReturn(new InlineResponse201()); + + svnfmService.createVnf(createVnfRequest); + + final String body = (new ObjectMapper()).valueToTree(createVnfRequest).toString(); + this.mockMvc + .perform(post("/svnfm/vnf_instances").content(body).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON)); + } +} + + |