| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4412563 commit f2efbce
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,9 +70,10 @@ env: | |||
| 70 | 70 | smoke/test_password_server | |
| 71 | 71 | smoke/test_portable_publicip | |
| 72 | 72 | smoke/test_portforwardingrules" | |
| 73 | - | ||
| 74 | - - TESTS="smoke/test_primary_storage | ||
| 75 | - smoke/test_privategw_acl | ||
| 73 | + | ||
| 74 | + - TESTS="smoke/test_primary_storage" | ||
| 75 | + | ||
| 76 | + - TESTS="smoke/test_privategw_acl | ||
| 76 | 77 | smoke/test_projects | |
| 77 | 78 | smoke/test_public_ip_range | |
| 78 | 79 | smoke/test_pvlan | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,10 +17,10 @@ | |||
| 17 | 17 | package org.apache.cloudstack.api.command.admin.storage; | |
| 18 | 18 | ||
| 19 | 19 | import java.util.ArrayList; | |
| 20 | + import java.util.Collections; | ||
| 21 | + import java.util.Comparator; | ||
| 20 | 22 | import java.util.List; | |
| 21 | 23 | ||
| 22 | - import org.apache.log4j.Logger; | ||
| 23 | - | ||
| 24 | 24 | import org.apache.cloudstack.api.APICommand; | |
| 25 | 25 | import org.apache.cloudstack.api.ApiCommandJobType; | |
| 26 | 26 | import org.apache.cloudstack.api.ApiConstants; | |
@@ -29,12 +29,14 @@ | |||
| 29 | 29 | import org.apache.cloudstack.api.response.ListResponse; | |
| 30 | 30 | import org.apache.cloudstack.api.response.StoragePoolResponse; | |
| 31 | 31 | import org.apache.cloudstack.api.response.VolumeResponse; | |
| 32 | + import org.apache.commons.lang3.StringUtils; | ||
| 33 | + import org.apache.log4j.Logger; | ||
| 32 | 34 | ||
| 33 | 35 | import com.cloud.storage.StoragePool; | |
| 34 | 36 | import com.cloud.utils.Pair; | |
| 35 | 37 | ||
| 36 | 38 | @APICommand(name = "findStoragePoolsForMigration", description = "Lists storage pools available for migration of a volume.", responseObject = StoragePoolResponse.class, | |
| 37 | - requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) | ||
| 39 | + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) | ||
| 38 | 40 | public class FindStoragePoolsForMigrationCmd extends BaseListCmd { | |
| 39 | 41 | public static final Logger s_logger = Logger.getLogger(FindStoragePoolsForMigrationCmd.class.getName()); | |
| 40 | 42 | ||
@@ -81,7 +83,7 @@ public void execute() { | |||
| 81 | 83 | StoragePoolResponse poolResponse = _responseGenerator.createStoragePoolForMigrationResponse(pool); | |
| 82 | 84 | Boolean suitableForMigration = false; | |
| 83 | 85 | for (StoragePool suitablePool : suitablePoolList) { | |
| 84 | - if (suitablePool.getId() == pool.getId()) { | ||
| 86 | + if (StringUtils.equals(suitablePool.getUuid(), pool.getUuid())) { | ||
| 85 | 87 | suitableForMigration = true; | |
| 86 | 88 | break; | |
| 87 | 89 | } | |
@@ -90,9 +92,27 @@ public void execute() { | |||
| 90 | 92 | poolResponse.setObjectName("storagepool"); | |
| 91 | 93 | poolResponses.add(poolResponse); | |
| 92 | 94 | } | |
| 93 | - | ||
| 95 | + sortPoolsBySuitabilityAndName(poolResponses); | ||
| 94 | 96 | response.setResponses(poolResponses); | |
| 95 | 97 | response.setResponseName(getCommandName()); | |
| 96 | 98 | this.setResponseObject(response); | |
| 97 | 99 | } | |
| 100 | + | ||
| 101 | + protected void sortPoolsBySuitabilityAndName(List<StoragePoolResponse> poolResponses) { | ||
| 102 | + Collections.sort(poolResponses, new Comparator<StoragePoolResponse>() { | ||
| 103 | + @Override | ||
| 104 | + public int compare(StoragePoolResponse o1, StoragePoolResponse o2) { | ||
| 105 | + if (o1.getSuitableForMigration() && o2.getSuitableForMigration()) { | ||
| 106 | + return o1.getName().compareTo(o2.getName()); | ||
| 107 | + } | ||
| 108 | + if (o1.getSuitableForMigration()) { | ||
| 109 | + return -1; | ||
| 110 | + } | ||
| 111 | + if (o2.getSuitableForMigration()) { | ||
| 112 | + return 1; | ||
| 113 | + } | ||
| 114 | + return 0; | ||
| 115 | + } | ||
| 116 | + }); | ||
| 117 | + } | ||
| 98 | 118 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,63 @@ | |||
| 1 | + // Licensed to the Apache Software Foundation (ASF) under one | ||
| 2 | + // or more contributor license agreements. See the NOTICE file | ||
| 3 | + // distributed with this work for additional information | ||
| 4 | + // regarding copyright ownership. The ASF licenses this file | ||
| 5 | + // to you under the Apache License, Version 2.0 (the | ||
| 6 | + // "License"); you may not use this file except in compliance | ||
| 7 | + // with the License. You may obtain a copy of the License at | ||
| 8 | + // | ||
| 9 | + // http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + // | ||
| 11 | + // Unless required by applicable law or agreed to in writing, | ||
| 12 | + // software distributed under the License is distributed on an | ||
| 13 | + // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| 14 | + // KIND, either express or implied. See the License for the | ||
| 15 | + // specific language governing permissions and limitations | ||
| 16 | + // under the License. | ||
| 17 | + package org.apache.cloudstack.api.command.admin.storage; | ||
| 18 | + | ||
| 19 | + import java.util.ArrayList; | ||
| 20 | + import java.util.List; | ||
| 21 | + | ||
| 22 | + import org.apache.cloudstack.api.response.StoragePoolResponse; | ||
| 23 | + import org.junit.Assert; | ||
| 24 | + import org.junit.Test; | ||
| 25 | + import org.junit.runner.RunWith; | ||
| 26 | + import org.mockito.runners.MockitoJUnitRunner; | ||
| 27 | + | ||
| 28 | + @RunWith(MockitoJUnitRunner.class) | ||
| 29 | + public class FindStoragePoolsForMigrationCmdTest { | ||
| 30 | + | ||
| 31 | + private FindStoragePoolsForMigrationCmd findStoragePoolsForMigrationCmd = new FindStoragePoolsForMigrationCmd(); | ||
| 32 | + | ||
| 33 | + @Test | ||
| 34 | + public void sortPoolsBySuitability() { | ||
| 35 | + List<StoragePoolResponse> storagePoolsResponse = new ArrayList<>(); | ||
| 36 | + StoragePoolResponse storagePoolResponse1 = new StoragePoolResponse(); | ||
| 37 | + storagePoolResponse1.setSuitableForMigration(true); | ||
| 38 | + storagePoolResponse1.setId("1"); | ||
| 39 | + storagePoolResponse1.setName("1"); | ||
| 40 | + | ||
| 41 | + StoragePoolResponse storagePoolResponse2 = new StoragePoolResponse(); | ||
| 42 | + storagePoolResponse2.setSuitableForMigration(false); | ||
| 43 | + storagePoolResponse2.setId("2"); | ||
| 44 | + storagePoolResponse2.setName("2"); | ||
| 45 | + | ||
| 46 | + StoragePoolResponse storagePoolResponse3 = new StoragePoolResponse(); | ||
| 47 | + storagePoolResponse3.setSuitableForMigration(true); | ||
| 48 | + storagePoolResponse3.setId("3"); | ||
| 49 | + storagePoolResponse3.setName("3"); | ||
| 50 | + | ||
| 51 | + storagePoolsResponse.add(storagePoolResponse3); | ||
| 52 | + storagePoolsResponse.add(storagePoolResponse2); | ||
| 53 | + storagePoolsResponse.add(storagePoolResponse1); | ||
| 54 | + | ||
| 55 | + findStoragePoolsForMigrationCmd.sortPoolsBySuitabilityAndName(storagePoolsResponse); | ||
| 56 | + | ||
| 57 | + Assert.assertEquals("1", storagePoolsResponse.get(0).getId()); | ||
| 58 | + Assert.assertEquals("3", storagePoolsResponse.get(1).getId()); | ||
| 59 | + Assert.assertEquals("2", storagePoolsResponse.get(2).getId()); | ||
| 60 | + | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments