Skip to content

Commit 116e06e

Browse files
committed
Merge branch 'master' into ui-restyle
2 parents 2edd97e + 81d078f commit 116e06e

26 files changed

Lines changed: 255 additions & 62 deletions

File tree

‎api/src/com/cloud/server/ResourceTag.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public enum TaggedResourceType {
4141
StaticRoute,
4242
VMSnapshot,
4343
RemoteAccessVpn,
44-
Zone
44+
Zone,
45+
ServiceOffering
4546
}
4647

4748
/**

‎api/src/org/apache/cloudstack/api/ApiConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ public class ApiConstants {
518518
public static final String ROUTING = "isrouting";
519519
public static final String MAX_CONNECTIONS = "maxconnections";
520520
public static final String SERVICE_STATE = "servicestate";
521+
public static final String RESOURCE_TAG = "resourcetag";
521522
public enum HostDetails {
522523
all, capacity, events, stats, min;
523524
}

‎api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,25 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.offering;
1818

19+
import java.util.Collection;
20+
import java.util.HashMap;
21+
import java.util.Iterator;
22+
import java.util.Map;
23+
1924
import org.apache.cloudstack.api.APICommand;
2025
import org.apache.cloudstack.api.ApiConstants;
2126
import org.apache.cloudstack.api.BaseListCmd;
2227
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.BaseCmd.CommandType;
2329
import org.apache.cloudstack.api.response.DomainResponse;
2430
import org.apache.cloudstack.api.response.ListResponse;
2531
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
2632
import org.apache.cloudstack.api.response.UserVmResponse;
2733

2834
import org.apache.log4j.Logger;
2935

36+
import com.cloud.exception.InvalidParameterValueException;
37+
3038
@APICommand(name = "listServiceOfferings", description="Lists all available service offerings.", responseObject=ServiceOfferingResponse.class)
3139
public class ListServiceOfferingsCmd extends BaseListCmd {
3240
public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName());
@@ -57,6 +65,9 @@ public class ListServiceOfferingsCmd extends BaseListCmd {
5765

5866
@Parameter(name=ApiConstants.SYSTEM_VM_TYPE, type=CommandType.STRING, description="the system VM type. Possible types are \"consoleproxy\", \"secondarystoragevm\" or \"domainrouter\".")
5967
private String systemVmType;
68+
69+
@Parameter(name = ApiConstants.RESOURCE_TAG, type = CommandType.MAP, description = "List service offerings by resource tags (key/value pairs)", since="4.3")
70+
private Map resourceTag;
6071

6172

6273
/////////////////////////////////////////////////////
@@ -86,6 +97,25 @@ public Boolean getIsSystem() {
8697
public String getSystemVmType(){
8798
return systemVmType;
8899
}
100+
101+
public Map<String, String> getResourceTags() {
102+
Map<String, String> tagsMap = null;
103+
if (resourceTag != null && !resourceTag.isEmpty()) {
104+
tagsMap = new HashMap<String, String>();
105+
Collection<?> servicesCollection = resourceTag.values();
106+
Iterator<?> iter = servicesCollection.iterator();
107+
while (iter.hasNext()) {
108+
HashMap<String, String> services = (HashMap<String, String>) iter.next();
109+
String key = services.get("key");
110+
String value = services.get("value");
111+
if (value == null) {
112+
throw new InvalidParameterValueException("No value is passed in for key " + key);
113+
}
114+
tagsMap.put(key, value);
115+
}
116+
}
117+
return tagsMap;
118+
}
89119

90120
/////////////////////////////////////////////////////
91121
/////////////// API Implementation///////////////////
@@ -98,7 +128,6 @@ public String getCommandName() {
98128

99129
@Override
100130
public void execute(){
101-
102131
ListResponse<ServiceOfferingResponse> response = _queryService.searchForServiceOfferings(this);
103132
response.setResponseName(getCommandName());
104133
this.setResponseObject(response);

‎api/src/org/apache/cloudstack/api/response/ServiceOfferingResponse.java‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@
1717
package org.apache.cloudstack.api.response;
1818

1919
import java.util.Date;
20-
21-
22-
import com.google.gson.annotations.SerializedName;
23-
20+
import java.util.LinkedHashSet;
2421
import java.util.Map;
25-
22+
import java.util.Set;
2623

2724
import org.apache.cloudstack.api.ApiConstants;
2825
import org.apache.cloudstack.api.BaseResponse;
2926
import org.apache.cloudstack.api.EntityReference;
3027

3128
import com.cloud.offering.ServiceOffering;
3229
import com.cloud.serializer.Param;
30+
import com.google.gson.annotations.SerializedName;
3331

3432
@EntityReference(value = ServiceOffering.class)
3533
public class ServiceOfferingResponse extends BaseResponse {
@@ -108,6 +106,15 @@ public class ServiceOfferingResponse extends BaseResponse {
108106
@SerializedName(ApiConstants.SERVICE_OFFERING_DETAILS)
109107
@Param(description = "additional key/value details tied with this service offering", since = "4.2.0")
110108
private Map<String, String> details;
109+
110+
@SerializedName(ApiConstants.RESOURCE_TAG) @Param(description="the list of resource tags associated with service offering." +
111+
" The resource tags are not used for Volume/VM placement on the specific host.",
112+
responseObject = ResourceTagResponse.class, since="4.3")
113+
private Set<ResourceTagResponse> resourceTags;
114+
115+
public ServiceOfferingResponse(){
116+
resourceTags = new LinkedHashSet<ResourceTagResponse>();
117+
}
111118

112119
public String getId() {
113120
return id;
@@ -287,4 +294,8 @@ public void setIopsWriteRate(Long iopsWriteRate) {
287294
public void setDetails(Map<String, String> details) {
288295
this.details = details;
289296
}
297+
298+
public void addTag(ResourceTagResponse tag){
299+
this.resourceTags.add(tag);
300+
}
290301
}

‎engine/schema/src/com/cloud/upgrade/dao/Upgrade307to410.java‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@
1818
package com.cloud.upgrade.dao;
1919

2020
import java.io.File;
21+
import java.io.FileInputStream;
22+
import java.io.IOException;
2123
import java.sql.Connection;
2224
import java.sql.PreparedStatement;
2325
import java.sql.SQLException;
26+
import java.util.Properties;
2427

28+
import com.cloud.utils.PropertiesUtil;
29+
import com.cloud.utils.crypt.EncryptionSecretKeyChecker;
2530
import org.apache.log4j.Logger;
2631

2732
import com.cloud.utils.db.Transaction;
2833
import com.cloud.utils.exception.CloudRuntimeException;
2934
import com.cloud.utils.script.Script;
35+
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
36+
import org.jasypt.properties.EncryptableProperties;
3037

3138
public class Upgrade307to410 implements DbUpgrade {
3239
final static Logger s_logger = Logger.getLogger(Upgrade307to410.class);
@@ -62,7 +69,28 @@ public void performDataMigration(Connection conn) {
6269
}
6370

6471
private void updateRegionEntries(Connection conn) {
65-
int region_id = Transaction.s_region_id;
72+
File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
73+
final Properties dbProps;
74+
if (EncryptionSecretKeyChecker.useEncryption()) {
75+
StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
76+
dbProps = new EncryptableProperties(encryptor);
77+
} else {
78+
dbProps = new Properties();
79+
}
80+
try {
81+
dbProps.load(new FileInputStream(dbPropsFile));
82+
} catch (IOException e) {
83+
s_logger.fatal("Unable to load db properties file, pl. check the classpath and file path configuration", e);
84+
return;
85+
} catch (NullPointerException e) {
86+
s_logger.fatal("Unable to locate db properties file within classpath or absolute path: db.properties");
87+
return;
88+
}
89+
int region_id = 1;
90+
String regionId = dbProps.getProperty("region.id");
91+
if(regionId != null){
92+
region_id = Integer.parseInt(regionId);
93+
}
6694
PreparedStatement pstmt = null;
6795
try {
6896
//Update regionId in region table

‎engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@
1717

1818
package com.cloud.upgrade.dao;
1919

20+
import com.cloud.utils.PropertiesUtil;
21+
import com.cloud.utils.crypt.EncryptionSecretKeyChecker;
2022
import com.cloud.utils.db.Transaction;
2123
import com.cloud.utils.exception.CloudRuntimeException;
2224
import com.cloud.utils.script.Script;
2325
import org.apache.log4j.Logger;
26+
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
27+
import org.jasypt.properties.EncryptableProperties;
2428

2529
import java.io.File;
30+
import java.io.FileInputStream;
31+
import java.io.IOException;
2632
import java.sql.Connection;
2733
import java.sql.PreparedStatement;
2834
import java.sql.ResultSet;
2935
import java.sql.SQLException;
36+
import java.util.Properties;
3037
import java.util.UUID;
3138

3239
public class Upgrade40to41 implements DbUpgrade {
@@ -74,7 +81,28 @@ public File[] getCleanupScripts() {
7481
}
7582

7683
private void updateRegionEntries(Connection conn) {
77-
int region_id = Transaction.s_region_id;
84+
File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
85+
final Properties dbProps;
86+
if (EncryptionSecretKeyChecker.useEncryption()) {
87+
StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
88+
dbProps = new EncryptableProperties(encryptor);
89+
} else {
90+
dbProps = new Properties();
91+
}
92+
try {
93+
dbProps.load(new FileInputStream(dbPropsFile));
94+
} catch (IOException e) {
95+
s_logger.fatal("Unable to load db properties file, pl. check the classpath and file path configuration", e);
96+
return;
97+
} catch (NullPointerException e) {
98+
s_logger.fatal("Unable to locate db properties file within classpath or absolute path: db.properties");
99+
return;
100+
}
101+
int region_id = 1;
102+
String regionId = dbProps.getProperty("region.id");
103+
if(regionId != null){
104+
region_id = Integer.parseInt(regionId);
105+
}
78106
PreparedStatement pstmt = null;
79107
try {
80108
//Update regionId in region table

‎engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
public interface RegionDao extends GenericDao<RegionVO, Integer> {
2424

2525
RegionVO findByName(String name);
26-
26+
int getRegionId();
2727
}

‎engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public RegionVO findByName(String name) {
4545
sc.setParameters("name", name);
4646
return findOneBy(sc);
4747
}
48+
49+
@Override
50+
public int getRegionId(){
51+
return 1;
52+
}
4853
}

‎framework/db/src/com/cloud/utils/db/GenericDao.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ public interface GenericDao<T, ID extends Serializable> {
265265
*/
266266
Class<T> getEntityBeanType();
267267

268-
public int getRegionId();
269-
270268
/**
271269
* @param sc
272270
* @param filter

‎framework/db/src/com/cloud/utils/db/GenericDaoBase.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,11 +1796,6 @@ public SearchCriteria<T> createSearchCriteria() {
17961796
return builder.create();
17971797
}
17981798

1799-
@Override
1800-
public int getRegionId(){
1801-
return Transaction.s_region_id;
1802-
}
1803-
18041799
public Integer getCount(SearchCriteria<T> sc) {
18051800
String clause = sc != null ? sc.getWhereClause() : null;
18061801
if (clause != null && clause.length() == 0) {

0 commit comments

Comments
 (0)