/*
 * Copyright 2002-2015 the original author or authors.
 *
 * 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 com.zuoxiaolong.niubi.job.service.impl;

import com.zuoxiaolong.niubi.job.api.data.StandbyNodeData;
import com.zuoxiaolong.niubi.job.core.helper.LoggerHelper;
import com.zuoxiaolong.niubi.job.core.helper.ReflectHelper;
import com.zuoxiaolong.niubi.job.service.StandbyNodeService;
import com.zuoxiaolong.niubi.job.service.view.StandbyNodeView;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Xiaolong Zuo
 * @since 1/15/2016 12:04
 */
@Service
public class MasterSlaveNodeServiceImpl extends AbstractService implements StandbyNodeService {

    @Override
    public List<StandbyNodeView> getAllNodes() {
        List<StandbyNodeData> standbyNodeDataList;
        List<StandbyNodeView> standbyNodeViewList = new ArrayList<>();
        try {
            standbyNodeDataList = standbyApiFactory.nodeApi().getAllNodes();
        } catch (Exception e) {
            LoggerHelper.warn("select all standby nodes failed, has been ignored [" + e.getClass().getName() + ", " + e.getMessage() + "]");
            return standbyNodeViewList;
        }
        for (StandbyNodeData standbyNodeData : standbyNodeDataList) {
            StandbyNodeView standbyNodeView = new StandbyNodeView();
            standbyNodeView.setId(standbyNodeData.getId());
            if (standbyNodeData.getData() != null) {
                ReflectHelper.copyFieldValues(standbyNodeData.getData(), standbyNodeView);
            }
            standbyNodeViewList.add(standbyNodeView);
        }
        return standbyNodeViewList;
    }

}

@@ -707,23 +707,27 @@
 pi.data.
-Standby
+MasterSlave
 NodeData
@@ -888,23 +888,27 @@
 service.
-Standby
+MasterSlave
 NodeServ
@@ -958,23 +958,22 @@
 ce.view.
-Standby
+Master
 NodeView
@@ -1216,23 +1216,27 @@
 lements 
-Standby
+MasterSlave
 NodeServ
@@ -1268,31 +1268,30 @@
 public List%3C
-Standby
+Master
 NodeView%3E ge
@@ -1321,32 +1321,40 @@
 ist%3C
-StandbyNodeData%3E standby
+MasterSlaveNodeData%3E masterSlave
 Node
@@ -1376,23 +1376,22 @@
    List%3C
-Standby
+Master
 NodeView
@@ -1392,23 +1392,22 @@
 deView%3E 
-standby
+master
 NodeView
@@ -1454,31 +1454,35 @@
             
-standby
+masterSlave
 NodeDataList
@@ -1484,23 +1484,27 @@
 aList = 
-standby
+masterSlave
 ApiFacto
@@ -1715,39 +1715,38 @@
          return 
-standby
+master
 NodeViewList;%0A  
@@ -1770,49 +1770,61 @@
 or (
-StandbyNodeData standbyNodeData : standby
+MasterSlaveNodeData masterSlaveNodeData : masterSlave
 Node
@@ -1847,23 +1847,22 @@
         
-Standby
+Master
 NodeView
@@ -1862,23 +1862,22 @@
 odeView 
-standby
+master
 NodeView
@@ -1887,15 +1887,14 @@
 new 
-Standby
+Master
 Node
@@ -1905,39 +1905,38 @@
 ();%0A            
-standby
+master
 NodeView.setId(s
@@ -1934,23 +1934,27 @@
 w.setId(
-standby
+masterSlave
 NodeData
@@ -1980,23 +1980,27 @@
     if (
-standby
+masterSlave
 NodeData
@@ -2067,23 +2067,27 @@
 dValues(
-standby
+masterSlave
 NodeData
@@ -2098,23 +2098,22 @@
 Data(), 
-standby
+master
 NodeView
@@ -2141,23 +2141,22 @@
         
-standby
+master
 NodeView
@@ -2164,23 +2164,22 @@
 ist.add(
-standby
+master
 NodeView
@@ -2206,23 +2206,22 @@
  return 
-standby
+master
 NodeView

modify names.