/*******************************************************************************
 * Copyright 2014 Open Networking Laboratory
 *
 * 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.
 ******************************************************************************/
package net.onrc.openvirtex.api.service.handlers.tenant;

import java.util.HashMap;
import java.util.Map;

import net.onrc.openvirtex.api.service.handlers.ApiHandler;
import net.onrc.openvirtex.api.service.handlers.HandlerUtils;
import net.onrc.openvirtex.api.service.handlers.TenantHandler;
import net.onrc.openvirtex.elements.OVXMap;
import net.onrc.openvirtex.elements.network.OVXNetwork;
import net.onrc.openvirtex.exceptions.InvalidTenantIdException;
import net.onrc.openvirtex.exceptions.MissingRequiredField;
import net.onrc.openvirtex.exceptions.NetworkMappingException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.thetransactioncompany.jsonrpc2.JSONRPC2Error;
import com.thetransactioncompany.jsonrpc2.JSONRPC2ParamsType;
import com.thetransactioncompany.jsonrpc2.JSONRPC2Response;

public class StartOVXNetwork extends ApiHandler<Map<String, Object>> {

    Logger log = LogManager.getLogger(StartOVXNetwork.class.getName());

    @Override
    public JSONRPC2Response process(final Map<String, Object> params) {
        JSONRPC2Response resp = null;

        try {
            final Number tenantId = HandlerUtils.<Number>fetchField(
                    TenantHandler.TENANT, params, true, null);

            HandlerUtils.isValidTenantId(tenantId.intValue());

            final OVXMap map = OVXMap.getInstance();
            final OVXNetwork virtualNetwork = map.getVirtualNetwork(tenantId
                    .intValue());

            virtualNetwork.boot();
            this.log.info("Booted virtual network {}",
                    virtualNetwork.getTenantId());
            Map<String, Object> reply = new HashMap<String, Object>(
                    virtualNetwork.getDBObject());
            resp = new JSONRPC2Response(reply, 0);

        } catch (final MissingRequiredField e) {
            resp = new JSONRPC2Response(new JSONRPC2Error(
                    JSONRPC2Error.INVALID_PARAMS.getCode(), this.cmdName()
                            + ": Unable to start virtual network : "
                            + e.getMessage()), 0);
        } catch (final InvalidTenantIdException e) {
            resp = new JSONRPC2Response(new JSONRPC2Error(
                    JSONRPC2Error.INVALID_PARAMS.getCode(), this.cmdName()
                            + ": Invalid tenant id : " + e.getMessage()), 0);
        } catch (final NetworkMappingException e) {
            resp = new JSONRPC2Response(new JSONRPC2Error(
                    JSONRPC2Error.INVALID_PARAMS.getCode(), this.cmdName()
                            + ": " + e.getMessage()), 0);
        }
        return resp;
    }

    @Override
    public JSONRPC2ParamsType getType() {
        return JSONRPC2ParamsType.OBJECT;
    }
}

@@ -2238,33 +2238,33 @@
   .intValue());%0A
-%0A
+ 
             virt
@@ -2250,33 +2250,40 @@
 ));%0A            
- 
+%0A%09%09%09if (
 virtualNetwork.b
@@ -2285,28 +2285,167 @@
 ork.
-boot();%0A            
+isBooted()) %7B%0A%09%09%09%09this.log.info(%22This virtual network %7B%7D has already started%22,%0A%09%09%09%09%09%09virtualNetwork.getTenantId());%0A%09%09%09%7D else %7B%0A%09%09%09%09virtualNetwork.boot();%0A%09%09%09%09
 this
@@ -2483,36 +2483,22 @@
 rk %7B%7D%22,%0A
-                    
+%09%09%09%09%09%09
 virtualN
@@ -2520,28 +2520,24 @@
 tId());%0A
-            
+%09%09%09%7D%0A%09%09%09
 Map%3CStri
@@ -2585,36 +2585,21 @@
 bject%3E(%0A
-                    
+%09%09%09%09%09
 virtualN
@@ -2621,28 +2621,19 @@
 ect());%0A
-            
+%09%09%09
 resp = n

Fix when executing "startNetwork" command will let the instance work incorrectly.