Skip to content

Commit aa2fb70

Browse files
authored
Merge branch 'main' into ldapCleanup
2 parents 234f78e + b09f3e8 commit aa2fb70

File tree

17 files changed

+146
-37
lines changed

17 files changed

+146
-37
lines changed

engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void removeUsage(Long accountId, Long vmId, Long backupOfferingId, Date e
6868
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), eventDate));
6969
pstmt.setLong(2, accountId);
7070
pstmt.setLong(3, vmId);
71-
pstmt.setLong(3, backupOfferingId);
71+
pstmt.setLong(4, backupOfferingId);
7272
pstmt.executeUpdate();
7373
}
7474
} catch (SQLException e) {

engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,11 @@ CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('router_health_check', 'check_result', '
2626
-- Increase length of scripts_version column to 128 due to md5sum to sha512sum change
2727
CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('cloud.domain_router', 'scripts_version', 'scripts_version', 'VARCHAR(128)');
2828

29+
-- Add uuid column to ldap_configuration table
30+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.ldap_configuration', 'uuid', 'VARCHAR(40) NOT NULL');
31+
32+
-- Populate uuid for existing rows where uuid is NULL or empty
33+
UPDATE `cloud`.`ldap_configuration` SET uuid = UUID() WHERE uuid IS NULL OR uuid = '';
34+
2935
-- Add the column cross_zone_instance_creation to cloud.backup_repository. if enabled it means that new Instance can be created on all Zones from Backups on this Repository.
3036
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backup_repository', 'cross_zone_instance_creation', 'TINYINT(1) DEFAULT NULL COMMENT ''Backup Repository can be used for disaster recovery on another zone''');

plugins/hypervisors/external/src/main/java/org/apache/cloudstack/hypervisor/external/provisioner/ExternalPathPayloadProvisioner.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ public class ExternalPathPayloadProvisioner extends ManagerBase implements Exter
103103
BASE_EXTERNAL_PROVISIONER_SCRIPTS_DIR + "/provisioner.sh";
104104

105105
private static final String PROPERTIES_FILE = "server.properties";
106+
private static final String EXTENSIONS = "extensions";
106107
private static final String EXTENSIONS_DEPLOYMENT_MODE_NAME = "extensions.deployment.mode";
107108
private static final String EXTENSIONS_DIRECTORY_PROD = "/usr/share/cloudstack-management/extensions";
108-
private static final String EXTENSIONS_DATA_DIRECTORY_PROD = "/var/lib/cloudstack/management/extensions";
109-
private static final String EXTENSIONS_DIRECTORY_DEV = "extensions";
109+
private static final String EXTENSIONS_DATA_DIRECTORY_PROD = System.getProperty("user.home") + File.separator + EXTENSIONS;
110+
private static final String EXTENSIONS_DIRECTORY_DEV = EXTENSIONS;
110111
private static final String EXTENSIONS_DATA_DIRECTORY_DEV = "client/target/extensions-data";
111112

112113
@Inject

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ public class LdapDeleteConfigurationCmd extends BaseCmd {
4040
@Inject
4141
private LdapManager _ldapManager;
4242

43+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, required = false, entityType = LdapConfigurationResponse.class, description = "ID of the LDAP configuration")
44+
private Long id;
4345

44-
@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, required = true, description = "Hostname")
46+
@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, description = "Hostname")
4547
private String hostname;
4648

4749
@Parameter(name = ApiConstants.PORT, type = CommandType.INTEGER, description = "port")
@@ -71,6 +73,10 @@ public Long getDomainId() {
7173
return domainId;
7274
}
7375

76+
public Long getId() {
77+
return id;
78+
}
79+
7480
@Override
7581
public void execute() throws ServerApiException {
7682
try {

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class LdapListConfigurationCmd extends BaseListCmd {
5454
description = "linked domain")
5555
private Long domainId;
5656

57+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = LdapConfigurationResponse.class, description = "list ldap configuration by ID; when passed, all other parameters are ignored")
58+
private Long id;
59+
5760
@Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN,
5861
description = "If set to true, and no `domainid` specified, list all LDAP configurations irrespective of the linked domain",
5962
since = "4.13.2")
@@ -122,6 +125,10 @@ public void setDomainId(final Long domainId) {
122125
this.domainId = domainId;
123126
}
124127

128+
public Long getId() {
129+
return id;
130+
}
131+
125132
public boolean listAll() {
126133
return listAll != null && listAll;
127134
}

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/response/LdapConfigurationResponse.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323

2424
import com.cloud.serializer.Param;
2525
import org.apache.cloudstack.api.EntityReference;
26-
import org.apache.cloudstack.ldap.LdapConfiguration;
26+
import org.apache.cloudstack.ldap.LdapConfigurationVO;
2727

28-
@EntityReference(value = LdapConfiguration.class)
28+
@EntityReference(value = LdapConfigurationVO.class)
2929
public class LdapConfigurationResponse extends BaseResponse {
30+
@SerializedName("id")
31+
@Param(description = "the ID of the LDAP configuration")
32+
private String id;
33+
3034
@SerializedName(ApiConstants.HOST_NAME)
3135
@Param(description = "name of the host running the ldap server")
3236
private String hostname;
@@ -53,9 +57,18 @@ public LdapConfigurationResponse(final String hostname, final int port) {
5357
setPort(port);
5458
}
5559

56-
public LdapConfigurationResponse(final String hostname, final int port, final String domainId) {
60+
public LdapConfigurationResponse(final String hostname, final int port, final String domainId, final String id) {
5761
this(hostname, port);
5862
setDomainId(domainId);
63+
setId(id);
64+
}
65+
66+
public String getId() {
67+
return id;
68+
}
69+
70+
public void setId(String id) {
71+
this.id = id;
5972
}
6073

6174
public String getHostname() {

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapConfigurationVO.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,40 @@
2323
import javax.persistence.Id;
2424
import javax.persistence.Table;
2525

26+
import org.apache.cloudstack.api.Identity;
2627
import org.apache.cloudstack.api.InternalIdentity;
2728

29+
import java.util.UUID;
30+
2831
@Entity
2932
@Table(name = "ldap_configuration")
30-
public class LdapConfigurationVO implements InternalIdentity {
31-
@Column(name = "hostname")
32-
private String hostname;
33-
33+
public class LdapConfigurationVO implements Identity, InternalIdentity {
3434
@Id
3535
@GeneratedValue(strategy = GenerationType.IDENTITY)
3636
@Column(name = "id")
3737
private Long id;
3838

39+
@Column(name = "hostname")
40+
private String hostname;
41+
42+
@Column(name = "uuid")
43+
private String uuid;
44+
3945
@Column(name = "port")
4046
private int port;
4147

4248
@Column(name = "domain_id")
4349
private Long domainId;
4450

4551
public LdapConfigurationVO() {
52+
this.uuid = UUID.randomUUID().toString();
4653
}
4754

4855
public LdapConfigurationVO(final String hostname, final int port, final Long domainId) {
4956
this.hostname = hostname;
5057
this.port = port;
5158
this.domainId = domainId;
59+
this.uuid = UUID.randomUUID().toString();
5260
}
5361

5462
public String getHostname() {
@@ -60,6 +68,10 @@ public long getId() {
6068
return id;
6169
}
6270

71+
public String getUuid() {
72+
return uuid;
73+
}
74+
6375
public int getPort() {
6476
return port;
6577
}

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.cloudstack.ldap.dao.LdapConfigurationDao;
5353
import org.apache.cloudstack.ldap.dao.LdapTrustMapDao;
5454
import org.apache.commons.lang.Validate;
55+
import org.apache.commons.lang3.StringUtils;
5556
import org.springframework.stereotype.Component;
5657

5758
import com.cloud.domain.DomainVO;
@@ -238,7 +239,7 @@ public LdapConfigurationResponse createLdapConfigurationResponse(final LdapConfi
238239
domainUuid = domain.getUuid();
239240
}
240241
}
241-
return new LdapConfigurationResponse(configuration.getHostname(), configuration.getPort(), domainUuid);
242+
return new LdapConfigurationResponse(configuration.getHostname(), configuration.getPort(), domainUuid, configuration.getUuid());
242243
}
243244

244245
@Override
@@ -255,6 +256,19 @@ public LdapUserResponse createLdapUserResponse(final LdapUser user) {
255256

256257
@Override
257258
public LdapConfigurationResponse deleteConfiguration(final LdapDeleteConfigurationCmd cmd) throws InvalidParameterValueException {
259+
Long id = cmd.getId();
260+
String hostname = cmd.getHostname();
261+
if (id == null && StringUtils.isEmpty(hostname)) {
262+
throw new InvalidParameterValueException("Either id or hostname must be specified");
263+
}
264+
if (id != null) {
265+
final LdapConfigurationVO config = _ldapConfigurationDao.findById(cmd.getId());
266+
if (config != null) {
267+
_ldapConfigurationDao.remove(config.getId());
268+
return createLdapConfigurationResponse(config);
269+
}
270+
throw new InvalidParameterValueException("Cannot find configuration with id " + id);
271+
}
258272
return deleteConfigurationInternal(cmd.getHostname(), cmd.getPort(), cmd.getDomainId());
259273
}
260274

@@ -375,7 +389,8 @@ public Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(fin
375389
final int port = cmd.getPort();
376390
final Long domainId = cmd.getDomainId();
377391
final boolean listAll = cmd.listAll();
378-
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId, listAll);
392+
final Long id = cmd.getId();
393+
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(id, hostname, port, domainId, listAll);
379394
return new Pair<>(result.first(), result.second());
380395
}
381396

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ public interface LdapConfigurationDao extends GenericDao<LdapConfigurationVO, Lo
3939

4040
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId);
4141

42-
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId, boolean listAll);
42+
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(Long id, String hostname, int port, Long domainId, boolean listAll);
4343
}

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDaoImpl.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public LdapConfigurationDaoImpl() {
4848
listGlobalConfigurationsSearch.done();
4949

5050
listDomainConfigurationsSearch = createSearchBuilder();
51+
listDomainConfigurationsSearch.and("id", listDomainConfigurationsSearch.entity().getId(), SearchCriteria.Op.EQ);
5152
listDomainConfigurationsSearch.and("hostname", listDomainConfigurationsSearch.entity().getHostname(), Op.EQ);
5253
listDomainConfigurationsSearch.and("port", listDomainConfigurationsSearch.entity().getPort(), Op.EQ);
5354
listDomainConfigurationsSearch.and("domain_id", listDomainConfigurationsSearch.entity().getDomainId(), Op.EQ);
@@ -63,25 +64,35 @@ public LdapConfigurationVO findByHostname(final String hostname) {
6364

6465
@Override
6566
public LdapConfigurationVO find(String hostname, int port, Long domainId) {
66-
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
67+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, false);
68+
return findOneBy(sc);
69+
}
70+
71+
@Override
72+
public LdapConfigurationVO find(String hostname, int port, Long domainId, boolean listAll) {
73+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, listAll);
6774
return findOneBy(sc);
6875
}
6976

7077
@Override
7178
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId) {
72-
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
79+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, false);
7380
return searchAndCount(sc, null);
7481
}
7582

7683
@Override
77-
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId, final boolean listAll) {
78-
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll);
84+
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final Long id, final String hostname, final int port, final Long domainId, final boolean listAll) {
85+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(id, hostname, port, domainId, listAll);
7986
return searchAndCount(sc, null);
8087
}
8188

82-
private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String hostname, int port, Long domainId,boolean listAll) {
89+
private SearchCriteria<LdapConfigurationVO> getSearchCriteria(Long id, String hostname, int port, Long domainId,boolean listAll) {
8390
SearchCriteria<LdapConfigurationVO> sc;
84-
if (domainId != null) {
91+
if (id != null) {
92+
// If id is present, ignore all other parameters
93+
sc = listDomainConfigurationsSearch.create();
94+
sc.setParameters("id", id);
95+
} else if (domainId != null) {
8596
// If domainid is present, ignore listall
8697
sc = listDomainConfigurationsSearch.create();
8798
sc.setParameters("domain_id", domainId);

0 commit comments

Comments
 (0)