// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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.
package org.apache.cloudstack.api.command.user.vpn;

import org.apache.log4j.Logger;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse;
import org.apache.cloudstack.api.response.VpcResponse;

import com.cloud.event.EventTypes;
import com.cloud.network.Site2SiteVpnGateway;
import com.cloud.network.vpc.Vpc;

@APICommand(name = "createVpnGateway", description = "Creates site to site vpn local gateway", responseObject = Site2SiteVpnGatewayResponse.class, entityType = {Site2SiteVpnGateway.class},
        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class CreateVpnGatewayCmd extends BaseAsyncCmd {
    public static final Logger s_logger = Logger.getLogger(CreateVpnGatewayCmd.class.getName());

    private static final String s_name = "createvpngatewayresponse";

    /////////////////////////////////////////////////////
    //////////////// API parameters /////////////////////
    /////////////////////////////////////////////////////
    @Parameter(name = ApiConstants.VPC_ID,
               type = CommandType.UUID,
               entityType = VpcResponse.class,
               required = true,
               description = "public ip address id of the vpn gateway")
    private Long vpcId;

    @Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the vpn to the end user or not", since = "4.4", authorized = {RoleType.Admin})
    private Boolean display;

    /////////////////////////////////////////////////////
    /////////////////// Accessors ///////////////////////
    /////////////////////////////////////////////////////

    public Long getVpcId() {
        return vpcId;
    }

    @Deprecated
    public Boolean getDisplay() {
        return display;
    }

    @Override
    public boolean isDisplay() {
        if (display != null) {
            return display;
        } else {
            return true;
        }
    }

    /////////////////////////////////////////////////////
    /////////////// API Implementation///////////////////
    /////////////////////////////////////////////////////

    @Override
    public String getCommandName() {
        return s_name;
    }

    @Override
    public long getEntityOwnerId() {
        Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
        return vpc.getAccountId();
    }

    @Override
    public String getEventDescription() {
        return "Create site-to-site VPN gateway for account " + getEntityOwnerId();
    }

    @Override
    public String getEventType() {
        return EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE;
    }

    @Override
    public void execute() {
        Site2SiteVpnGateway result;
        result = _s2sVpnService.createVpnGateway(this);
        if (result != null) {
            Site2SiteVpnGatewayResponse response = _responseGenerator.createSite2SiteVpnGatewayResponse(result);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPN gateway");
        }
    }

    @Override
    public String getSyncObjType() {
        return BaseAsyncCmd.vpcSyncObject;
    }

    @Override
    public Long getSyncObjId() {
        return getVpcId();
    }
}

@@ -858,34 +858,172 @@
 ort 
-org.apache.log4j.Logger
+com.cloud.event.EventTypes;%0Aimport com.cloud.exception.ResourceAllocationException;%0Aimport com.cloud.network.Site2SiteVpnGateway;%0Aimport com.cloud.network.vpc.Vpc
 ;%0A
-%0A
 impo
@@ -1247,16 +1247,69 @@
 yncCmd;%0A
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;%0A
 import o
@@ -1527,122 +1527,88 @@
 se;%0A
-%0A
 import 
-com.cloud.event.EventTypes;%0Aimport com.cloud.network.Site2SiteVpnGateway;%0Aimport com.cloud.network.vpc.Vpc
+org.apache.cloudstack.context.CallContext;%0Aimport org.apache.log4j.Logger
 ;%0A%0A@
@@ -1921,16 +1921,22 @@
 seAsyncC
+reateC
 md %7B%0A   
@@ -3961,32 +3961,115 @@
 ute() %7B%0A        
+CallContext.current().setEventDetails(%22VPN gateway Id: %22 + getEntityId());%0A        
 Site2SiteVpnGate
@@ -4075,24 +4075,8 @@
 eway
- result;%0A       
  res
@@ -4096,22 +4096,19 @@
 Service.
-create
+get
 VpnGatew
@@ -4110,20 +4110,29 @@
 Gateway(
-this
+getEntityId()
 );%0A     
@@ -4647,24 +4647,24 @@
 ncObjId() %7B%0A
-
         retu
@@ -4683,11 +4683,416 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void create() throws ResourceAllocationException %7B%0A        Site2SiteVpnGateway result = _s2sVpnService.createVpnGateway(this);%0A        if (result != null) %7B%0A            setEntityId(result.getId());%0A            setEntityUuid(result.getUuid());%0A        %7D else %7B%0A            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, %22Failed to create VPN gateway%22);%0A        %7D%0A    %7D
 %0A%7D%0A

Make CreateVpnGatewayCmd implements BaseAsyncCreateCmd