/**
*  Copyright 2014 IBM
*
*   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.
*/

var topologyPoolModel = require('../models/poolmodel');
var Topology = require('../models/topologymodel');
var minstance= require('../models/instancemodel');



exports.findAllView = function(req, res) {
   console.log('req.params.id:'+req.params.id);
   minstance.find({poolRef:req.params.id}, function(err, instances) {
   if (err) {
     console.log ( 'error get instances associated with pool');
     console.err(err);
     return;
   }   
   res.render('topology/instances/instanceindex', {
      title: 'Associated Instances',
      docs: instances
    });
  });
};

exports.findAll = function(req, res) {
   console.log('req.params.id:'+req.params.id);
   minstance.find({poolRef:req.params.id}, function(err, instances) {
   if (err) {
     console.log ( 'error get instances associated with pool');
     console.err(err);
     res.send(404);
     return;
   }   
   res.send(instances);
  });
};

exports.find = function(req, res) {
   console.log('req.params.id:'+req.params.id);
   minstance.findById(req.params.id, function(err, instance) {
   if (err) {
     console.log ( 'error get instance');
     console.err(err);
     res.send(404);
     return;
   }   
   res.send(instance);
  });
};



exports.deleteView = function(req, res) {
   console.log('req.params.id:'+req.params.id);
   minstance.findById(req.params.id, function(err, instance) {
   if (err) {
     console.log ( 'error get instance to remove');
     console.err(err);
     return;
   }   
   res.render('topology/instances/instanceindex', {
      title: 'Associated Instances',
      docs: instances
    });
  });
};


@@ -1237,32 +1237,172 @@
 req.params.id);%0A
+   topologyPoolModel.count(%7B_id:req.params.id%7D, function(err, count) %7B%0A%09%09console.log('::::count of pool:'+count);%0A%09%09if (count==1) %7B %0A       
    minstance.fin
@@ -1447,32 +1447,39 @@
 r, instances) %7B%0A
+       
    if (err) %7B%0A  
@@ -1468,32 +1468,39 @@
      if (err) %7B%0A
+       
      console.log
@@ -1544,32 +1544,39 @@
 th pool');%0A     
+    
+   
 console.err(err)
@@ -1569,32 +1569,39 @@
 nsole.err(err);%0A
+       
      res.send(40
@@ -1596,32 +1596,39 @@
  res.send(404);%0A
+       
      return;%0A   
@@ -1619,37 +1619,51 @@
      return;%0A   
-%7D   %0A
+       %7D   %0A       
    res.send(inst
@@ -1670,16 +1670,78 @@
 ances);%0A
+          %7D);%0A        %7D %0A        else%0A         res.send(404);%0A
   %7D);%0A%7D;
@@ -1818,32 +1818,224 @@
 req.params.id);%0A
+   console.log('req.params.pid:'+req.params.pid);%0A   topologyPoolModel.count(%7B_id:req.params.pid%7D, function(err, count) %7B%0A%09%09console.log('::::count of pool:'+count);%0A%09%09if (count==1) %7B %0A        
    minstance.fin
@@ -2073,32 +2073,40 @@
 rr, instance) %7B%0A
+        
    if (err) %7B%0A  
@@ -2100,32 +2100,40 @@
 if (err) %7B%0A     
+    
+    
 console.log ( 'e
@@ -2149,24 +2149,32 @@
 instance');%0A
+        
      console
@@ -2180,24 +2180,32 @@
 e.err(err);%0A
+        
      res.sen
@@ -2208,24 +2208,32 @@
 .send(404);%0A
+        
      return;
@@ -2240,33 +2240,109 @@
 %0A   
-%7D   %0A   res.send(instance
+        %7D   %0A           res.send(instance);%0A           %7D);%0A       %7D%0A       else%0A         res.send(404
 );%0A 

update instance api implementation