/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package web.component.impl.aws.model;

import java.util.ArrayList;
import java.util.List;
import web.component.api.model.Instance;
import web.component.api.model.Subnet;
import web.component.api.model.VPC;
import web.component.api.model.Zone;
import web.component.impl.aws.AWS;
import web.component.impl.aws.AWSAutoScaling;
import web.component.impl.aws.AWSEC2;
import web.component.impl.aws.AWSELB;

/**
 *
 * @author Hiroshi
 */
public class AWSResouceFactory {
 
    public static List<Instance> getExistInstances(){
        
       List<com.amazonaws.services.ec2.model.Instance> ec2Instances = AWS.access().ec2().getExistEc2Instances();
        List<Instance> instances = new ArrayList<>();
        for(com.amazonaws.services.ec2.model.Instance ec2Instance : ec2Instances)
            instances.add(new InstanceImpl.Builder().id(ec2Instance.getInstanceId()).get());
        return instances;
    }

    public static Instance createDefaultInstance(){
        
        String instanceId = AWS.access().ec2().createDefaultInstance().getInstanceId();
        return new InstanceImpl.Builder().id(instanceId).get();
    }

    public static List<Zone> getExistZones(){
        
        List<com.amazonaws.services.ec2.model.AvailabilityZone> ec2Zones  = AWS.access().ec2().getExistEc2AvailabilityZones();
        List<Zone> zones = new ArrayList<>();
        for(com.amazonaws.services.ec2.model.AvailabilityZone ec2Zone : ec2Zones)
            zones.add(new ZoneImpl.Builder().name(ec2Zone.getZoneName()).build());
        return zones;
    }
    
    public static List<VPC> getExistVPCs(){
        List<com.amazonaws.services.ec2.model.Vpc> ec2Vpcs = AWS.access().ec2().getExistEc2Vpcs();
        List<VPC> vpcs = new ArrayList<>();
        for(com.amazonaws.services.ec2.model.Vpc ec2Vpc : ec2Vpcs)
            vpcs.add(new VPCImpl.Builder().id(ec2Vpc.getVpcId()).get());
        return vpcs;
    }
    
    public static List<Subnet> getExistSubnets(){
        List<com.amazonaws.services.ec2.model.Subnet> ec2Subnets = AWS.access().ec2().getExistEc2Subnets();
        List<Subnet> subnets = new ArrayList<>();
        for(com.amazonaws.services.ec2.model.Subnet ec2Subnet : ec2Subnets)
            subnets.add(new SubnetImpl.Builder().id(ec2Subnet.getSubnetId()).get());
        return subnets;
    }
}

@@ -310,16 +310,61 @@
 stance;%0A
+import web.component.api.model.LoadBalancer;%0A
 import w
@@ -505,130 +505,8 @@
 AWS;
-%0Aimport web.component.impl.aws.AWSAutoScaling;%0Aimport web.component.impl.aws.AWSEC2;%0Aimport web.component.impl.aws.AWSELB;
 %0A%0A/*
@@ -568,16 +568,44 @@
 ory %7B%0A %0A
+   /*%0A    * instance%0A    */%0A
     publ
@@ -632,21 +632,16 @@
 nce%3E get
-Exist
 Instance
@@ -1020,32 +1020,137 @@
 nstances;%0A    %7D%0A
+    public Instance getInstance(String id)%7B%0A        return new InstanceImpl.Builder().id(id).get();%0A    %7D
 %0A    public stat
@@ -1354,16 +1354,40 @@
 %0A    %7D%0A%0A
+   /*%0A    * zone%0A    */%0A
     publ
@@ -1410,21 +1410,16 @@
 one%3E get
-Exist
 Zones()%7B
@@ -1790,32 +1790,164 @@
 ones;%0A    %7D%0A    
+public static Zone getZone(String name)%7B%0A        return new ZoneImpl.Builder().name(name).build();%0A    %7D%0A    %0A   /*%0A    * vpc%0A    */
 %0A    public stat
@@ -1962,21 +1962,16 @@
 VPC%3E get
-Exist
 VPCs()%7B%0A
@@ -2280,24 +2280,148 @@
 ;%0A    %7D%0A    
+public static VPC getVPC(String id)%7B%0A        return new VPCImpl.Builder().id(id).get();%0A    %7D%0A    %0A   /*%0A    * subnet%0A    */
 %0A    public 
@@ -2443,21 +2443,16 @@
 net%3E get
-Exist
 Subnets(
@@ -2803,10 +2803,409 @@
 ;%0A    %7D%0A
-%7D
+    public static Subnet getSubnet(String id)%7B%0A        return new SubnetImpl.Builder().id(id).get();%0A    %7D%0A    %0A   /*%0A    * load balancer%0A    */%0A    public static List%3CLoadBalancer%3E getLoadBalancers()%7B%0A        return LoadBalancerImpl.getExistLoadBalancers();%0A    %7D%0A    public static LoadBalancer getLoadBalancer(String name)%7B%0A        return LoadBalancerImpl.getExistLoadBalancerByName(name);%0A    %7D%0A%7D%0A
 %0A

add methods to AWSResourceFactory.