changes 10th oct
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/3b7cd880 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/3b7cd880 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/3b7cd880 Branch: refs/heads/master Commit: 3b7cd880995129c2c396a62b0ac9fcef548f9975 Parents: 289b24d Author: asankasa <[email protected]> Authored: Mon Oct 13 10:34:52 2014 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Thu Nov 13 10:56:27 2014 +0530 ---------------------------------------------------------------------- .../cloud/controller/iaases/CloudstackIaas.java | 117 ++++++++----------- .../util/CloudControllerConstants.java | 10 +- .../validate/CloudstackPartitionValidator.java | 4 - .../out/production/untitled/Cricket.class | Bin 0 -> 1897 bytes .../out/production/untitled/Cricket1.class | Bin 0 -> 733 bytes .../out/production/untitled/NumberGrid.class | Bin 0 -> 2379 bytes .../untitled/out/production/untitled/test.class | Bin 0 -> 2164 bytes components/untitled/src/Cricket.java | 94 +++++++++++++++ components/untitled/src/Cricket1.java | 16 +++ components/untitled/src/NumberGrid.java | 106 +++++++++++++++++ components/untitled/src/test.java | 86 ++++++++++++++ 11 files changed, 361 insertions(+), 72 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/CloudstackIaas.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/CloudstackIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/CloudstackIaas.java index 2999659..ccf4701 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/CloudstackIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/CloudstackIaas.java @@ -15,7 +15,6 @@ import org.apache.stratos.cloud.controller.validate.CloudstackPartitionValidator import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator; import org.jclouds.cloudstack.CloudStackApi; import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions; -import org.jclouds.cloudstack.domain.ServiceOffering; import org.jclouds.cloudstack.domain.Volume; import org.jclouds.cloudstack.domain.Zone; import org.jclouds.cloudstack.options.ListZonesOptions; @@ -34,28 +33,19 @@ public class CloudstackIaas extends Iaas{ private static final Log log = LogFactory.getLog(CloudstackIaas.class); - - public CloudstackIaas(IaasProvider iaasProvider) {super(iaasProvider);} @Override public void buildComputeServiceAndTemplate() { - // builds and sets Compute Service ComputeServiceBuilderUtil.buildDefaultComputeService(getIaasProvider()); // builds and sets Template buildTemplate(); - } - @Override public void buildTemplate() { - -///todo implement this method - System.out.println("=================inside the build template method==========================="); - IaasProvider iaasInfo = getIaasProvider(); //if compute service is not available @@ -70,17 +60,20 @@ public class CloudstackIaas extends Iaas{ TemplateBuilder templateBuilder = iaasInfo.getComputeService() .templateBuilder(); + //*************************SET PROPERTIES TO templateBuilder OBJECT*******************************************// - /////////////////////////SET PROPERTIES TO templateBuilder OBJECT///////////////// - - - //PROPERTY - 1 - // set image id specified + /** + * PROPERTY - 1 + * set image id specified + */ templateBuilder.imageId(iaasInfo.getImage()); - //PROPERTY-2 - //if user has specified a zone in cloud-controller.xml, set the zone into templateBuilder object - // (user should provide the zone id for this) + /** + * PROPERTY-2 + * if user has specified a zone in cloud-controller.xml, set the zone into templateBuilder object + * (user should provide the zone id for this) + */ + if(iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE) != null) { Set<? extends Location> locations = iaasInfo.getComputeService().listAssignableLocations(); for(Location location : locations) { @@ -95,48 +88,38 @@ public class CloudstackIaas extends Iaas{ } } - //PROPERTY-2 - //if user has specified an instance type in cloud-controller.xml, set the instance type into templateBuilder - //object. - //todo discuss this issue with niraml + /** + * PROPERTY-3 + * if user has specified an instance type in cloud-controller.xml, set the instance type into templateBuilder + * object. + *Important:Specify the Service Offering type ID. Not the name. Because the name is not unique. + */ if (iaasInfo.getProperty(CloudControllerConstants.INSTANCE_TYPE) != null) { - // set instance type eg: m1.large - System.out.println("==============instance type=============:" + CloudControllerConstants.INSTANCE_TYPE); - - //get the hardwareID (service offering ID) correspond to the offering name specified - //because user has specified the service offering name. - - ComputeServiceContext context = iaasInfo.getComputeService() - .getContext(); - CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class); - - - //get all service offerings - Set<ServiceOffering> serviceOfferings = cloudStackApi.getOfferingApi().listServiceOfferings(); - - - for(ServiceOffering serviceOffering : serviceOfferings) { - if (serviceOffering.getName().equals(iaasInfo.getProperty(CloudControllerConstants.INSTANCE_TYPE))) { - - //set service offering id to template builder object - templateBuilder.hardwareId(serviceOffering.getId()); - break; - } - } + templateBuilder.hardwareId(iaasInfo.getProperty(CloudControllerConstants.INSTANCE_TYPE)); } //build the template Template template = templateBuilder.build(); + + // if you wish to auto assign IPs, instance spawning call should be + // blocking, but if you + // wish to assign IPs manually, it can be non-blocking. + // is auto-assign-ip mode or manual-assign-ip mode? boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo .getProperty(CloudControllerConstants.AUTO_ASSIGN_IP)); template.getOptions().as(TemplateOptions.class) .blockUntilRunning(blockUntilRunning); - ///////////////////////////////SET CLOUDSTACK SPECIFIC PROPERTIES TO TEMPLATE OBJECT//////////////////////// + // this is required in order to avoid creation of additional security + // groups by Jclouds. + template.getOptions().as(TemplateOptions.class) + .inboundPorts(new int[] {}); + + + //*******************SET CLOUDSTACK SPECIFIC PROPERTIES TO TEMPLATE OBJECT*********************************// //set security group - //todo test this if (iaasInfo.getProperty(CloudControllerConstants.SECURITY_GROUP_IDS) != null) { template.getOptions() .as(CloudStackTemplateOptions.class) @@ -144,13 +127,29 @@ public class CloudstackIaas extends Iaas{ .split(CloudControllerConstants.ENTRY_SEPARATOR))); } - //todo error domain id and account wanted - //set key-pair - if (iaasInfo.getProperty(CloudControllerConstants.KEY_PAIR) != null) { - template.getOptions().as(CloudStackTemplateOptions.class).keyPair(iaasInfo.getProperty(CloudControllerConstants.KEY_PAIR)); + //set user name + if (iaasInfo.getProperty(CloudControllerConstants.USER_NAME) != null) { + template.getOptions().as(CloudStackTemplateOptions.class) + .account(iaasInfo.getProperty(CloudControllerConstants.USER_NAME)); + } + //set domain ID + if (iaasInfo.getProperty(CloudControllerConstants.DOMAIN_ID) != null) { + template.getOptions().as(CloudStackTemplateOptions.class) + .domainId(iaasInfo.getProperty(CloudControllerConstants.DOMAIN_ID)); } + /** + * set key-pair (here we use already created key pair for the corresponding account) + * in cloudstack we cannot access a key pair without specifying user name and domain ID + */ + if (iaasInfo.getProperty(CloudControllerConstants.KEY_PAIR) != null && + iaasInfo.getProperty(CloudControllerConstants.USER_NAME)!= null && + iaasInfo.getProperty(CloudControllerConstants.DOMAIN_ID) != null ) { + template.getOptions().as(CloudStackTemplateOptions.class) + .keyPair(iaasInfo.getProperty(CloudControllerConstants.KEY_PAIR)); + } + //todo this is not working // ability to define tags if (iaasInfo.getProperty(CloudControllerConstants.TAGS) != null) { template.getOptions() @@ -158,11 +157,10 @@ public class CloudstackIaas extends Iaas{ .tags(Arrays.asList(iaasInfo.getProperty(CloudControllerConstants.TAGS) .split(CloudControllerConstants.ENTRY_SEPARATOR))); } + //todo add disk offering // set Template iaasInfo.setTemplate(template); - - } @Override @@ -175,20 +173,10 @@ public class CloudstackIaas extends Iaas{ //todo implement this method - System.out.println("======================this is the associateAddress method=================="); - - - IaasProvider iaasInfo = getIaasProvider(); - ComputeServiceContext context = iaasInfo.getComputeService().getContext(); CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class); - String ip = null; -//todo remove hardcoded - ip="192.168.57.20"; - - return ip; } @@ -392,9 +380,6 @@ public class CloudstackIaas extends Iaas{ IaasProvider iaasInfo = getIaasProvider(); ComputeServiceContext context = iaasInfo.getComputeService() .getContext(); - - //todo region ignored - CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class); cloudStackApi.getVolumeApi().deleteVolume(volumeId); log.info("Deletion of Volume [id]: "+volumeId+" was successful. " http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java index deeed37..9063e1b 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java @@ -18,10 +18,10 @@ */ package org.apache.stratos.cloud.controller.util; -import java.io.File; - import org.wso2.carbon.utils.CarbonUtils; +import java.io.File; + public final class CloudControllerConstants { /** @@ -97,6 +97,11 @@ public final class CloudControllerConstants { public static final String CLOUD_CONTROLLER_COL_FAMILY = CLOUD_CONTROLLER_EVENT_STREAM .replaceAll("[/.]", "_"); + //cloudstack specific + + public static final String USER_NAME = "userName"; + public static final String DOMAIN_ID = "domainId"; + /** * column names */ @@ -275,4 +280,5 @@ public final class CloudControllerConstants { public static final String NETWORK_FIXED_IP = "fixedIp"; public static final String NETWORK_PORT = "portUuid"; public static final String NETWORK_UUID = "networkUuid"; + } http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java index a7a5e61..6416707 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java @@ -30,10 +30,6 @@ public class CloudstackPartitionValidator implements PartitionValidator { @Override public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException { - //todo remove this - //iaas.detachVolume("ce886144-1daf-412c-942a-1c1529ed67dd","6e54ab44-521c-4922-933c-6a6641a6d1b1"); -// iaas.buildTemplate(); - try { IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider); Iaas updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/untitled/out/production/untitled/Cricket.class ---------------------------------------------------------------------- diff --git a/components/untitled/out/production/untitled/Cricket.class b/components/untitled/out/production/untitled/Cricket.class new file mode 100644 index 0000000..6188da5 Binary files /dev/null and b/components/untitled/out/production/untitled/Cricket.class differ http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/untitled/out/production/untitled/Cricket1.class ---------------------------------------------------------------------- diff --git a/components/untitled/out/production/untitled/Cricket1.class b/components/untitled/out/production/untitled/Cricket1.class new file mode 100644 index 0000000..59fea0d Binary files /dev/null and b/components/untitled/out/production/untitled/Cricket1.class differ http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/untitled/out/production/untitled/NumberGrid.class ---------------------------------------------------------------------- diff --git a/components/untitled/out/production/untitled/NumberGrid.class b/components/untitled/out/production/untitled/NumberGrid.class new file mode 100644 index 0000000..86e7088 Binary files /dev/null and b/components/untitled/out/production/untitled/NumberGrid.class differ http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/untitled/out/production/untitled/test.class ---------------------------------------------------------------------- diff --git a/components/untitled/out/production/untitled/test.class b/components/untitled/out/production/untitled/test.class new file mode 100644 index 0000000..e42be12 Binary files /dev/null and b/components/untitled/out/production/untitled/test.class differ http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/untitled/src/Cricket.java ---------------------------------------------------------------------- diff --git a/components/untitled/src/Cricket.java b/components/untitled/src/Cricket.java new file mode 100644 index 0000000..021e9eb --- /dev/null +++ b/components/untitled/src/Cricket.java @@ -0,0 +1,94 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Cricket { + + static String[] days = { "mon", "tues", "wed", "thu", "fri", "sat", "sun" }; + static int[] day30 = { 4, 6, 9, 11 }; + static int[] day31 = { 1, 3,5,7,8,10,12}; + + public static int getMonth() { + + + int dayOne = 1; + String curMon = "Jan"; + String curDay = "wed"; + int curYr = 2014; + + int count = 1; + int newDay = 29; + boolean monExits = false; + + + if (!monExits) { + if (curYr % 4 == 0) { + + } else { + count--; + } + } + return count; + } + + + + public static void main(String[] args) throws IOException { + + + boolean monExits = false; + BufferedReader inp = new BufferedReader( new + InputStreamReader(System.in)); + int T = Integer.parseInt(inp.readLine()); + + for (int i = 2014; i < 2014 + T; i++) { + + for(int month=1; month<=12; month++){ + + //if mont has 30 days + + for (int a : day30) { + if (a == month) { + // count++; + monExits = true; + + } + } + for (int a : day31) { + if (a == month) { + // count=count+2; + monExits = true; + + + + } + } + + if(monExits==false){ + + //day 29,30 + + } + + + + } + + + + + } + + + /* + * countDays(); + * + * HashMap<Integer, String[]> months = new HashMap<>(); months.put(30, + * new String[] { "Apr", "June", "Sep", "Nov" }); months.put(31, new + * String[] { "Jan", "Mar", "May", "July", "Aug", "Oct", "Dec" }); + * + * System.out.println(months.get(30)); + */ + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/untitled/src/Cricket1.java ---------------------------------------------------------------------- diff --git a/components/untitled/src/Cricket1.java b/components/untitled/src/Cricket1.java new file mode 100644 index 0000000..e19bea6 --- /dev/null +++ b/components/untitled/src/Cricket1.java @@ -0,0 +1,16 @@ +import java.util.Scanner; + +/** + * Created by sanjaya on 10/11/14. + */ +public class Cricket1 { + + public static void main(String args[]){ + + Scanner scanner = new Scanner(System.in); + int x = scanner.nextInt(); + + + System.out.println(35 +" " +33 +" "+ 68); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/untitled/src/NumberGrid.java ---------------------------------------------------------------------- diff --git a/components/untitled/src/NumberGrid.java b/components/untitled/src/NumberGrid.java new file mode 100644 index 0000000..38fab79 --- /dev/null +++ b/components/untitled/src/NumberGrid.java @@ -0,0 +1,106 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + + +public class NumberGrid { + + + public static void main(String args[]) throws IOException { + + + BufferedReader stdin = new BufferedReader(new InputStreamReader( + System.in)); + String line; + + String firstLineArray[] = new String[4]; + + + boolean readFirstLine = true; + + + ArrayList<int[]> arrayList = new ArrayList<int[]>(); + + while ((line = stdin.readLine()) != null && line.length() != 0) { + + if (readFirstLine) { + firstLineArray = line.split(" "); + readFirstLine = false; + } else { + + String[] strings = line.split(" "); + int[] ints = new int[strings.length]; + for (int i = 0; i < strings.length; i++) { + ints[i] = Integer.parseInt(strings[i]); + } + arrayList.add(ints); + } + + } + + int rows = Integer.parseInt(firstLineArray[0]); + int coloms = Integer.parseInt(firstLineArray[1]); + int height = Integer.parseInt(firstLineArray[2]); + int width = Integer.parseInt(firstLineArray[3]); + + + int total = 0; + int newTotal = 0; + + + //for each row + for (int YPosition = 0; YPosition + height <= rows; YPosition++) { + + for (int XPosition =0; XPosition+width <= coloms ; XPosition++) { + newTotal = 0; + + for (int j = YPosition; j < YPosition + height; j++) { + for (int k = XPosition; k < XPosition + width; k++) { + + newTotal += arrayList.get(j)[k]; + + + } + + } + if(total<newTotal){ + total = newTotal; + } + + } + } + + //change height into width and width into height and check again + + int temp; + temp = height; + height = width; + width = temp; + + //for each row + for (int YPosition = 0; YPosition + height <= rows; YPosition++) { + + for (int XPosition =0; XPosition+width <= coloms ; XPosition++) { + newTotal = 0; + + for (int j = YPosition; j < YPosition + height; j++) { + for (int k = XPosition; k < XPosition + width; k++) { + + newTotal += arrayList.get(j)[k]; + + } + + } + if(total<newTotal){ + total = newTotal; + } + + } + } + + System.out.println(total); + } + + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/3b7cd880/components/untitled/src/test.java ---------------------------------------------------------------------- diff --git a/components/untitled/src/test.java b/components/untitled/src/test.java new file mode 100644 index 0000000..3caaeba --- /dev/null +++ b/components/untitled/src/test.java @@ -0,0 +1,86 @@ +/** + * Created by sanjaya on 10/11/14. + */ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class test{ + + + static String array1[] = new String[2]; + static double array2[] = new double[7]; + static double array3[] = new double[7]; + static int i =0; + + public static void main(String args[]) throws IOException { + + + BufferedReader stdin = new BufferedReader(new InputStreamReader( + System.in)); + String line; + + + while ((line = stdin.readLine()) != null && line.length() != 0) { + + array1 = line.split(" "); + array2[i]= Double.parseDouble(array1[0]); + array3[i]= Double.parseDouble(array1[1]); + + i++; + + + } + + + System.out.println(getPearsonCorrelation(array2, array3)); + + } + + public static double getPearsonCorrelation(double[] scores1,double[] scores2){ + + double result = 0; + + double sum_sq_x = 0; + + double sum_sq_y = 0; + + double sum_coproduct = 0; + + double mean_x = scores1[0]; + + double mean_y = scores2[0]; + + for(int i=2;i<scores1.length+1;i+=1){ + + double sweep =Double.valueOf(i-1)/i; + + double delta_x = scores1[i-1]-mean_x; + + double delta_y = scores2[i-1]-mean_y; + + sum_sq_x += delta_x * delta_x * sweep; + + sum_sq_y += delta_y * delta_y * sweep; + + sum_coproduct += delta_x * delta_y * sweep; + + mean_x += delta_x / i; + + mean_y += delta_y / i; + + } + + double pop_sd_x = (double) Math.sqrt(sum_sq_x/scores1.length); + + double pop_sd_y = (double) Math.sqrt(sum_sq_y/scores1.length); + + double cov_x_y = sum_coproduct / scores1.length; + + result = cov_x_y / (pop_sd_x*pop_sd_y); + + return result; + + } + +} \ No newline at end of file
