/** * Copyright (C) 2015 Orange * 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. */ /** * Please modify this class to meet your needs * This class is not complete */ package com.francetelecom.clara.cloud.providersoap.environment.v3.service; import com.francetelecom.clara.cloud.core.service.ManageEnvironment; import com.francetelecom.clara.cloud.core.service.exception.ApplicationReleaseNotFoundException; import com.francetelecom.clara.cloud.core.service.exception.ObjectNotFoundException; import com.francetelecom.clara.cloud.core.service.exception.PaasUserNotFoundException; import com.francetelecom.clara.cloud.providersoap.mapping.SoapMapper; import com.francetelecom.clara.cloud.services.dto.EnvironmentDto; import com.francetelecom.clara.cloud.services.dto.EnvironmentDto.EnvironmentTypeEnum; import com.orange.clara.cloud.providersoap.environment.v3.exception.EnvironmentNotFoundError; import com.orange.clara.cloud.providersoap.environment.v3.exception.InvalidEnvironmentError; import com.orange.clara.cloud.providersoap.environment.v3.exception.PaasUserNotFoundError; import com.orange.clara.cloud.providersoap.environment.v3.exception.ReleaseNotFoundError; import com.orange.clara.cloud.providersoap.environment.v3.model.*; import com.orange.clara.cloud.providersoap.environment.v3.service.*; import com.orange.clara.cloud.providersoap.security.v1.Credentials; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.Assert; import java.util.ArrayList; import java.util.List; /** * This class was generated by Apache CXF * */ @javax.jws.WebService(serviceName = "PaasEnvironmentService", portName = "PaasEnvironmentServicePort", targetNamespace = "http://www.orange.com/paas/environment/v3/PaasEnvironmentService", endpointInterface = "com.orange.clara.cloud.providersoap.environment.v3.service.PaasEnvironmentService") @org.apache.cxf.annotations.SchemaValidation public class PaasEnvironmentServiceImpl implements PaasEnvironmentService { private static final Logger LOG = LoggerFactory.getLogger(PaasEnvironmentServiceImpl.class); // application layer service to manage an environment private ManageEnvironment manageEnvironment; // to map application layer service inputs/outputs to/from web services // inputs/outputs private SoapMapper mapper; /** * Create an Environment * * @param command * command to perform * * @param credentials * user credentials * @return The UUID of the environment which has been created * * @exception ReleaseNotFoundErrorFault * The corresponding release for this environment was not * found * @exception InvalidEnvironmentErrorFault * An error occurred preventing the environment from being * created */ @Override public java.lang.String createEnvironment(CreateEnvironmentCommand command, Credentials credentials) throws ReleaseNotFoundErrorFault, InvalidEnvironmentErrorFault, PaasUserNotFoundErrorFault { try { // environment type must not be empty Assert.hasText(command.getType().value(), "environment type must not be empty"); // release uid must not be empty Assert.hasText(command.getReleaseUID(), "release uid must not be empty"); // environment owner must not be empty Assert.notNull(credentials, "no credentials provided"); // environment label must not be empty Assert.hasText(command.getLabel(), "environment label must not be empty"); // we want to create an environment String environmentUID = manageEnvironment.createEnvironment(command.getReleaseUID(), mapper.map(command.getType(), EnvironmentTypeEnum.class), credentials.getSsoid(), command.getLabel()); return environmentUID; } catch (PaasUserNotFoundException e) { LOG.warn("exception : " + e); throw (PaasUserNotFoundErrorFault) mapper.map(e, PaasUserNotFoundErrorFault.class, PaasUserNotFoundError.class); } catch (ApplicationReleaseNotFoundException e) { LOG.warn("exception : " + e); throw (ReleaseNotFoundErrorFault) mapper.map(e, ReleaseNotFoundErrorFault.class, ReleaseNotFoundError.class); } catch (Exception e) { LOG.warn("exception : " + e); throw (InvalidEnvironmentErrorFault) mapper.map(e, InvalidEnvironmentErrorFault.class, InvalidEnvironmentError.class); } } /** * Stop an environment (providing it's UUID) * * @param command * command to perform * @param credentials * user credentials * * @exception EnvironmentNotFoundErrorFault * No environment was found for this UUID */ @Override public void stopEnvironment(StopEnvironmentCommand command, Credentials credentials) throws EnvironmentNotFoundErrorFault { try { Assert.notNull(command, "StopEnvironmentCommand should not be empty"); // environment uid must not be empty Assert.hasText(command.getUid(), "environment uid must not be empty"); // we want to stop an environment manageEnvironment.stopEnvironment(command.getUid()); } catch (ObjectNotFoundException e) { LOG.warn("exception : " + e); throw (EnvironmentNotFoundErrorFault) mapper.map(e, EnvironmentNotFoundErrorFault.class, EnvironmentNotFoundError.class); } } /** * Delete an environment (providing it's UUID) * * @param command * command to perform * @param credentials * user credentials * @exception EnvironmentNotFoundErrorFault * No environment was found for this UUID */ @Override public void deleteEnvironment(DeleteEnvironmentCommand command, Credentials credentials) throws EnvironmentNotFoundErrorFault { try { Assert.notNull(command, "DeleteEnvironmentCommand should not be empty"); Assert.hasText(command.getUid(), "environment uid must not be empty"); // we want to delete an environment manageEnvironment.deleteEnvironment(command.getUid()); } catch (ObjectNotFoundException e) { LOG.warn("exception : " + e); throw (EnvironmentNotFoundErrorFault) mapper.map(e, EnvironmentNotFoundErrorFault.class, EnvironmentNotFoundError.class); } } /** * Start an environment (providing it's UUID) * * @param command * command to perform * @param credentials * user credentials * @exception EnvironmentNotFoundErrorFault * No environment was found for this UUID */ @Override public void startEnvironment(StartEnvironmentCommand command, Credentials credentials) throws EnvironmentNotFoundErrorFault { try { Assert.notNull(command, "StartEnvironmentCommand should not be empty"); // environment uid must not be empty Assert.hasText(command.getUid(), "environment uid must not be empty"); // we want to start an environment manageEnvironment.startEnvironment(command.getUid()); } catch (ObjectNotFoundException e) { LOG.warn("exception : " + e); throw (EnvironmentNotFoundErrorFault) mapper.map(e, EnvironmentNotFoundErrorFault.class, EnvironmentNotFoundError.class); } } /** * Retrieve an environment (providing it's UUID) * * @param uid * The UUID of the environment to be retrieved * @param credentials * user credentials * @return EnvironmentModel The retrieved environment * * @exception EnvironmentNotFoundErrorFault * No environment was found for this UUID */ @Override public EnvironmentModel getEnvironment(String uid, Credentials credentials) throws EnvironmentNotFoundErrorFault { try { // environment uid must not be empty Assert.hasText(uid, "environment uid must not be empty"); // we want to get an environment EnvironmentDto source = manageEnvironment.findEnvironmentByUID(uid); return mapper.map(source, EnvironmentModel.class); } catch (ObjectNotFoundException e) { LOG.warn("exception : " + e); throw (EnvironmentNotFoundErrorFault) mapper.map(e, EnvironmentNotFoundErrorFault.class, EnvironmentNotFoundError.class); } } /** * List all available environment for a given release (providing it's UUID) * * @param releaseUID * The UUID of the release * @param credentials * user credentials * @return List<EnvironmentModel> The list of corresponding environments for * this release * * @exception ReleaseNotFoundErrorFault * No release was found for this UUID */ @Override public List<EnvironmentModel> findAndGetEnvironmentsByRelease(String releaseUID, Credentials credentials) throws ReleaseNotFoundErrorFault { try { // environment uid must not be empty Assert.hasText(releaseUID, "release uid must not be empty"); // we want to get an environment List<EnvironmentDto> source = manageEnvironment.findEnvironmentsByAppRelease(releaseUID); List<EnvironmentModel> target = new ArrayList<EnvironmentModel>(); for (EnvironmentDto environment : source) { target.add(mapper.map(environment, EnvironmentModel.class)); } // returns environment status return target; } catch (ApplicationReleaseNotFoundException e) { LOG.warn("exception : " + e); throw (ReleaseNotFoundErrorFault) mapper.map(e, ReleaseNotFoundErrorFault.class, ReleaseNotFoundError.class); } } /** * Get the status of a given environment (providing it's UUID) * * @param uid * The UUID of the environment for which the status is needed * @param credentials * user credentials * @exception EnvironmentNotFoundErrorFault * No environment was found for this UUID */ @Override public EnvironmentStatus getEnvironmentStatus(String uid, Credentials credentials) throws EnvironmentNotFoundErrorFault { try { // environment uid must not be empty Assert.hasText(uid, "environment uid must not be empty"); // we want to get an environment EnvironmentDto source = manageEnvironment.findEnvironmentByUID(uid); // returns environment status return mapper.map(source, EnvironmentStatus.class); } catch (ObjectNotFoundException e) { LOG.warn("exception : " + e); throw (EnvironmentNotFoundErrorFault) mapper.map(e, EnvironmentNotFoundErrorFault.class, EnvironmentNotFoundError.class); } } /** * Setter for a manageEnvironment * * @param manageEnvironment */ public void setManageEnvironment(ManageEnvironment manageEnvironment) { this.manageEnvironment = manageEnvironment; } /** * Setter for a mapper (Dozer) * * @param mapper */ public void setMapper(SoapMapper mapper) { this.mapper = mapper; } }