f125cbbc50c28fb97e7a213dcd3c939d0e532e5c
[so.git] / status-control / src / main / java / org / openecomp / mso / MsoStatusHandler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso;
22
23
24 import org.openecomp.mso.utils.UUIDChecker;
25 import org.openecomp.mso.logger.MessageEnum;
26 import org.openecomp.mso.logger.MsoLogger;
27 import org.openecomp.mso.requestsdb.RequestsDatabase;
28
29 import javax.ws.rs.*;
30 import javax.ws.rs.core.Response;
31
32 @Path("/")
33 public class MsoStatusHandler {
34     private MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
35
36     @POST
37     @Path("/setStatus/{siteName}")
38     @Produces("text/plain")
39     public Response setSiteStatus (@DefaultValue("true") @QueryParam("enable") Boolean enable,
40                                    @PathParam("siteName") String siteName) {
41         long startTime = System.currentTimeMillis();
42         // Set logger parameters
43         UUIDChecker.generateUUID (logger);
44         MsoLogger.setServiceName ("SetSiteStatus");
45
46
47         if (null == siteName) {
48             logger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Not able to find the site name attribute in the config file");
49             return Response.status (Response.Status.INTERNAL_SERVER_ERROR).entity ("Exception: not able to find the site name attribute in the config file").build ();
50         }
51
52         // Query DB for the value
53         try {
54                 RequestsDatabase.updateSiteStatus(siteName, enable);
55
56         } catch (Exception e) {
57             logger.error (MessageEnum.GENERAL_EXCEPTION, "", "setSiteStatus", MsoLogger.ErrorCode.DataError, "Failed to set site status", e);
58             logger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while updating site status");
59             return Response.status (Response.Status.INTERNAL_SERVER_ERROR).entity ("Exception while updating site status").build ();
60         }
61         logger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
62         return Response.status (Response.Status.OK).entity ("Site status successfully updated to " + enable).build ();
63     }
64 }