Refactor grpc package by placing the services in flat structure

Change-Id: Id1c8f7bb9a60b4d58898347816df5752f30a62a5
diff --git a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/app/package-info.java b/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/app/package-info.java
deleted file mode 100644
index b5cd387..0000000
--- a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/app/package-info.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2017-present Open Networking 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.
- */
-/**
- * gRPC server implementations for northbound services.
- */
-package org.onosproject.grpc.nb.app;
\ No newline at end of file
diff --git a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/net/meter/package-info.java b/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/net/meter/package-info.java
deleted file mode 100644
index 3b63c95..0000000
--- a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/net/meter/package-info.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2017-present Open Networking 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.
- */
-/**
- * gRPC server implementations for northbound services.
- */
-package org.onosproject.grpc.nb.net.meter;
\ No newline at end of file
diff --git a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/package-info.java b/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/package-info.java
deleted file mode 100644
index 9701cab..0000000
--- a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2017-present Open Networking 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.
- */
-
-/**
- * gRPC server implementations for northbound services.
- */
-package org.onosproject.grpc.nb;
\ No newline at end of file
diff --git a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/utils/GrpcNbMeterServiceUtil.java b/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/utils/GrpcNbMeterServiceUtil.java
deleted file mode 100644
index 43c4908..0000000
--- a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/utils/GrpcNbMeterServiceUtil.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Copyright 2017-present Open Networking 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.
- */
-package org.onosproject.grpc.nb.utils;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.onosproject.net.meter.Band;
-import org.onosproject.net.meter.MeterRequest;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.meter.DefaultBand;
-import org.onosproject.net.meter.DefaultMeterRequest;
-import org.onosproject.net.meter.Meter;
-import org.onosproject.net.meter.MeterState;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.DefaultApplicationId;
-import org.onosproject.grpc.core.models.ApplicationIdProtoOuterClass.ApplicationIdProto;
-import org.onosproject.grpc.net.meter.models.BandProtoOuterClass.BandProto;
-import org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterRequestTypeProto;
-import org.onosproject.grpc.net.meter.models.MeterRequestProtoOuterClass.MeterRequestProto;
-import org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterUnitProto;
-import org.onosproject.grpc.net.meter.models.BandEnumsProto.BandTypeProto;
-import org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterStateProto;
-import org.onosproject.grpc.net.meter.models.MeterProtoOuterClass.MeterProto;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.stream.Collectors;
-import com.google.common.annotations.Beta;
-
-/**
- * gRPC message conversion related utilities for meter service.
- */
-@Beta
-public final class GrpcNbMeterServiceUtil {
-    private static final Logger log = LoggerFactory.getLogger(GrpcNbMeterServiceUtil.class);
-
-    /**
-     * Translates gRPC ApplicationId to {@link ApplicationId}.
-     *
-     * @param gAppId gRPC message
-     * @return {@link ApplicationId}
-     */
-    public static ApplicationId translate(ApplicationIdProto gAppId) {
-        int id = gAppId.getId();
-        String name = gAppId.getName();
-        ApplicationId appId = new DefaultApplicationId(id, name);
-        return appId;
-    }
-
-    /**
-     * Translates gRPC Band to {@link Band}.
-     *
-     * @param gBand gRPC message
-     * @return {@link Band}
-     */
-    public static Band translate(BandProto gBand) {
-        Band.Type type = translate(gBand.getType());
-        long rate = gBand.getRate();
-        long burstSize = gBand.getBurst();
-        short prec = (short) gBand.getDropPrecedence();
-        Band band = new DefaultBand(type, rate, burstSize, prec);
-        return band;
-    }
-
-    /**
-     * Translates gRPC List Bands to Collection Band.
-     *
-     * @param listBands gRPC message
-     * @return Collection Band
-     */
-    public static Collection<Band> translate(java.util.List<BandProto>  listBands) {
-        Collection<Band> bands = new ArrayList<>();
-        listBands.forEach(d -> {
-            bands.add(translate(d));
-        });
-        return bands;
-    }
-
-    /**
-     * Translates gRPC MeterRequestType to {@link MeterRequest.Type}.
-     *
-     * @param type gRPC message
-     * @return {@link MeterRequest.Type}
-     */
-    public static MeterRequest.Type translate(MeterRequestTypeProto type) {
-        switch (type) {
-            case ADD:
-                return MeterRequest.Type.ADD;
-            case MODIFY:
-                return MeterRequest.Type.MODIFY;
-            case REMOVE:
-                return MeterRequest.Type.REMOVE;
-            case UNRECOGNIZED:
-                log.warn("Unrecognized MeterRequest type gRPC message: {}", type);
-                return null;
-            default:
-                log.warn("Unrecognized MeterRequest type gRPC message: {}", type);
-                return null;
-        }
-    }
-
-    /**
-     * Translates gRPC MeterRequest to {@link MeterRequest}.
-     *
-     * @param meterRequest gRPC message
-     * @return {@link MeterRequest}
-     */
-    public static MeterRequest translate(MeterRequestProto meterRequest) {
-
-        DeviceId deviceid = DeviceId.deviceId(meterRequest.getDeviceId());
-        ApplicationId appId = translate(meterRequest.getApplicationId());
-        Meter.Unit unit = translate(meterRequest.getUnit());
-        boolean burst = meterRequest.getIsBurst();
-        Collection<Band> bands = translate(meterRequest.getBandsList());
-        MeterRequest.Type type = translate(meterRequest.getType());
-        if (type == MeterRequest.Type.ADD) {
-            return DefaultMeterRequest.builder()
-                    .forDevice(deviceid)
-                    .fromApp(appId)
-                    .withUnit(unit)
-                    .withBands(bands)
-                    .add();
-        } else {
-            return DefaultMeterRequest.builder()
-                    .forDevice(deviceid)
-                    .fromApp(appId)
-                    .withUnit(unit)
-                    .withBands(bands)
-                    .remove();
-        }
-    }
-
-    /**
-     * Translates {@link ApplicationId} to gRPC ApplicationId message.
-     *
-     * @param appId {@link ApplicationId}
-     * @return gRPC ApplicationId message
-     */
-    public static ApplicationIdProto translate(ApplicationId appId) {
-        return ApplicationIdProto.newBuilder()
-                .setId(appId.id())
-                .setName(appId.name())
-                .build();
-    }
-
-    /**
-     * Translates gRPC enum MeterUnit to ONOS enum.
-     *
-     * @param unit meterUnit in gRPC enum
-     * @return equivalent in ONOS enum
-     */
-    public static Meter.Unit translate(MeterUnitProto unit) {
-        switch (unit) {
-            case PKTS_PER_SEC:
-                return Meter.Unit.PKTS_PER_SEC;
-            case KB_PER_SEC:
-                return Meter.Unit.KB_PER_SEC;
-            case UNRECOGNIZED:
-                log.warn("Unrecognized MeterUnit gRPC message: {}", unit);
-                return null;
-            default:
-                log.warn("Unrecognized MeterUnit gRPC message: {}", unit);
-                return null;
-        }
-    }
-
-    /**
-     * Translates ONOS enum Meter.Unit Type to gRPC enum.
-     *
-     * @param unit Meter.Unit in ONOS enum
-     * @return equivalent in gRPC enum
-     */
-    public static MeterUnitProto translate(Meter.Unit unit) {
-        switch (unit) {
-            case PKTS_PER_SEC:
-                return org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterUnitProto.PKTS_PER_SEC;
-            case KB_PER_SEC:
-                return org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterUnitProto.KB_PER_SEC;
-            default:
-                log.warn("Unrecognized MeterUnit ONOS message: {}", unit);
-                return org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterUnitProto.UNRECOGNIZED;
-        }
-    }
-
-    /**
-     * Translates gRPC enum Band Type to ONOS enum.
-     *
-     * @param bandType BandType in gRPC enum
-     * @return equivalent in ONOS enum
-     */
-    public static Band.Type translate(BandTypeProto bandType) {
-        switch (bandType) {
-            case DROP:
-                return Band.Type.DROP;
-            case REMARK:
-                return Band.Type.REMARK;
-            case EXPERIMENTAL:
-                return Band.Type.EXPERIMENTAL;
-            case UNRECOGNIZED:
-                log.warn("Unrecognized BandType gRPC message: {}", bandType);
-                return null;
-            default:
-                log.warn("Unrecognized BandType gRPC message: {}", bandType);
-                return null;
-        }
-    }
-
-    /**
-     * Translates ONOS enum Band Type to gRPC enum.
-     *
-     * @param bandType BandType in ONOS enum
-     * @return equivalent in gRPC enum
-     */
-    public static BandTypeProto translate(Band.Type bandType) {
-        switch (bandType) {
-            case DROP:
-                return org.onosproject.grpc.net.meter.models.BandEnumsProto.BandTypeProto.DROP;
-            case REMARK:
-                return org.onosproject.grpc.net.meter.models.BandEnumsProto.BandTypeProto.REMARK;
-            case EXPERIMENTAL:
-                return org.onosproject.grpc.net.meter.models.BandEnumsProto.BandTypeProto.EXPERIMENTAL;
-            default:
-                log.warn("Unrecognized BandType ONOS message: {}", bandType);
-                return null;
-        }
-    }
-
-    /**
-     * Translates ONOS enum MeterState Type to gRPC enum.
-     *
-     * @param meterState MeterState in ONOS enum
-     * @return equivalent in gRPC enum
-     */
-    public static MeterStateProto translate(MeterState meterState) {
-        switch (meterState) {
-            case PENDING_ADD:
-                return org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterStateProto.PENDING_ADD;
-            case ADDED:
-                return org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterStateProto.ADDED;
-            case PENDING_REMOVE:
-                return org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterStateProto.PENDING_REMOVE;
-            case REMOVED:
-                return org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterStateProto.REMOVED;
-            default:
-                log.warn("Unrecognized MeterState ONOS message: {}", meterState);
-                return org.onosproject.grpc.net.meter.models.MeterEnumsProto.MeterStateProto.UNRECOGNIZED;
-        }
-    }
-
-    /**
-     * Translates {@link Meter} to gRPC MeterCore message.
-     *
-     * @param meter {@link Meter}
-     * @return gRPC MeterCore message
-     */
-    public static MeterProto translate(Meter meter) {
-        return MeterProto.newBuilder()
-                .setDeviceId(meter.deviceId().toString())
-                .setApplicationId(translate(meter.appId()))
-                .setUnit(translate(meter.unit()))
-                .setIsBurst(meter.isBurst())
-                .addAllBands(meter.bands().stream()
-                        .map(b -> BandProto.newBuilder()
-                                .setRate(b.rate())
-                                .setBurst(b.burst())
-                                .setDropPrecedence(b.dropPrecedence())
-                                .setType(translate(b.type()))
-                                .setPackets(b.packets())
-                                .setBytes(b.bytes())
-                                .build())
-                        .collect(Collectors.toList()))
-                .setState(translate(meter.state()))
-                .setLife(meter.life())
-                .setReferenceCount(meter.referenceCount())
-                .setPacketsSeen(meter.packetsSeen())
-                .setBytesSeen(meter.bytesSeen())
-                .build();
-    }
-
-    // Utility class not intended for instantiation.
-    private GrpcNbMeterServiceUtil() {
-    }
-}
diff --git a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/utils/package-info.java b/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/utils/package-info.java
deleted file mode 100644
index 341744c..0000000
--- a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/utils/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2017-present Open Networking 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.
- */
-
-/**
- * A package contains a set of utilities that are used to convert gRPC model
- * object to ONOS data model object.
- */
-package org.onosproject.grpc.nb.utils;
\ No newline at end of file
diff --git a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/app/GrpcNbApplicationService.java b/incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbApplicationService.java
similarity index 97%
rename from incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/app/GrpcNbApplicationService.java
rename to incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbApplicationService.java
index 4bc5a31..9bbd813 100644
--- a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/app/GrpcNbApplicationService.java
+++ b/incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbApplicationService.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.grpc.nb.app;
+package org.onosproject.incubator.protobuf.services.nb;
 
 import com.google.common.annotations.Beta;
 import io.grpc.stub.StreamObserver;
@@ -27,6 +27,7 @@
 import org.onosproject.core.Application;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.grpc.nb.app.ApplicationServiceGrpc.ApplicationServiceImplBase;
+import org.onosproject.grpc.nb.app.ApplicationServiceNb;
 import org.onosproject.grpc.nb.app.ApplicationServiceNb.getApplicationReply;
 import org.onosproject.grpc.nb.app.ApplicationServiceNb.getApplicationsReply;
 import org.onosproject.grpc.nb.app.ApplicationServiceNb.getIdReply;
diff --git a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/net/meter/GrpcNbMeterService.java b/incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbMeterService.java
similarity index 87%
rename from incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/net/meter/GrpcNbMeterService.java
rename to incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbMeterService.java
index 64ced8a..c30accd 100644
--- a/incubator/protobuf/services/nb/src/main/java/org/onosproject/grpc/nb/net/meter/GrpcNbMeterService.java
+++ b/incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbMeterService.java
@@ -14,12 +14,12 @@
  * limitations under the License.
  */
 
-package org.onosproject.grpc.nb.net.meter;
+package org.onosproject.incubator.protobuf.services.nb;
 
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.onosproject.net.meter.MeterService;
-import org.onosproject.grpc.nb.utils.GrpcNbMeterServiceUtil;
+import org.onosproject.incubator.protobuf.models.net.meter.MeterProtoTranslator;
 
 import org.onosproject.grpc.nb.net.meter.MeterServiceGrpc.MeterServiceImplBase;
 import org.onosproject.grpc.nb.net.meter.MeterServiceNbProto.submitRequest;
@@ -46,7 +46,7 @@
 /**
  * A server that provides access to the methods exposed by {@link MeterService}.
  * TODO this requires major refactoring, translation should be delegated to calls to
- * TODO{@link GrpcNbMeterServiceUtil}.
+ * TODO{@link MeterProtoTranslator}.
  */
 @Beta
 @Component(immediate = true)
@@ -75,8 +75,8 @@
         public void submit(submitRequest request,
                            StreamObserver<submitReply> responseObserver) {
             submitReply.Builder replyBuilder = submitReply.newBuilder();
-            Meter meter = meterService.submit(GrpcNbMeterServiceUtil.translate(request.getMeter()));
-            responseObserver.onNext(replyBuilder.setSubmitMeter(GrpcNbMeterServiceUtil.translate(meter)).build());
+            Meter meter = meterService.submit(MeterProtoTranslator.translate(request.getMeter()));
+            responseObserver.onNext(replyBuilder.setSubmitMeter(MeterProtoTranslator.translate(meter)).build());
             responseObserver.onCompleted();
         }
 
@@ -84,7 +84,7 @@
         public void withdraw(withdrawRequest request,
                              StreamObserver<withdrawReply> responseObserver) {
             withdrawReply.Builder replyBuilder = withdrawReply.newBuilder();
-            meterService.withdraw(GrpcNbMeterServiceUtil.translate(request.getMeter()),
+            meterService.withdraw(MeterProtoTranslator.translate(request.getMeter()),
                     MeterId.meterId(request.getMeterId()));
             responseObserver.onNext(replyBuilder.build());
             responseObserver.onCompleted();
@@ -96,7 +96,7 @@
             getMeterReply.Builder replyBuilder = getMeterReply.newBuilder();
             Meter meter = meterService.getMeter(DeviceId.deviceId(request.getDeviceId()),
                     MeterId.meterId(request.getMeterId()));
-            responseObserver.onNext(replyBuilder.setMeter(GrpcNbMeterServiceUtil.translate(meter)).build());
+            responseObserver.onNext(replyBuilder.setMeter(MeterProtoTranslator.translate(meter)).build());
             responseObserver.onCompleted();
         }
 
@@ -105,7 +105,7 @@
                                  StreamObserver<getAllMetersReply> responseObserver) {
             getAllMetersReply.Builder replyBuilder = getAllMetersReply.newBuilder();
             meterService.getAllMeters().forEach(d -> {
-                replyBuilder.addMeters(GrpcNbMeterServiceUtil.translate(d));
+                replyBuilder.addMeters(MeterProtoTranslator.translate(d));
             });
             responseObserver.onNext(replyBuilder.build());
             responseObserver.onCompleted();
@@ -116,7 +116,7 @@
                               StreamObserver<getMetersReply> responseObserver) {
             getMetersReply.Builder replyBuilder = getMetersReply.newBuilder();
             meterService.getMeters(DeviceId.deviceId(request.getDeviceId())).forEach(d -> {
-                replyBuilder.addMeters(GrpcNbMeterServiceUtil.translate(d));
+                replyBuilder.addMeters(MeterProtoTranslator.translate(d));
             });
             responseObserver.onNext(replyBuilder.build());
             responseObserver.onCompleted();