Skip to content

Commit ebba161

Browse files
Reverting cloud UUIDs
Signed-off-by: Pratham Vaghela <prathamcomeslast@gmail.com>
1 parent bf30b66 commit ebba161

File tree

2 files changed

+8
-50
lines changed

2 files changed

+8
-50
lines changed

src/main/java/com/sap/prd/jenkins/plugins/agent_maintenance/MaintenanceAction.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public class MaintenanceAction implements Action {
4545
@Restricted(NoExternalUse.class)
4646
public static final Permission[] CONFIGURE_AND_DISCONNECT = new Permission[]{Computer.DISCONNECT, Computer.CONFIGURE};
4747

48-
/**
49-
* Creates MaintenanceAction. Including UUID for clouds.
50-
*/
5148
public MaintenanceAction(MaintenanceTarget target) {
5249
this.target = target;
5350
}
@@ -140,10 +137,10 @@ public boolean isEnabled() {
140137
* @return <code>Cloud</code> instance of the maintenance action.
141138
*/
142139
public Cloud getCloud() {
143-
if (!isCloud()) {
144-
return null;
140+
if (isCloud()) {
141+
return Jenkins.get().getCloud(target.getName());
145142
}
146-
return CloudUuidStore.getInstance().getCloudByTarget(target);
143+
return null;
147144
}
148145

149146
/**

src/main/java/com/sap/prd/jenkins/plugins/agent_maintenance/MaintenanceLink.java

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
public class MaintenanceLink extends ManagementLink {
4545
private static final Logger LOGGER = Logger.getLogger(MaintenanceLink.class.getName());
4646

47-
private static final CloudUuidStore CLOUD_UUID_STORE = CloudUuidStore.getInstance();
48-
4947
private transient Throwable error;
5048

5149
@Override
@@ -114,8 +112,7 @@ public List<MaintenanceAction> getTargets() throws IOException {
114112
// New: Adding clouds to the list
115113
for (Cloud cloud : j.clouds) {
116114
try {
117-
String uuid = CloudUuidStore.getInstance().getUuidIfPresent(cloud);
118-
MaintenanceTarget target = new MaintenanceTarget(MaintenanceTarget.TargetType.CLOUD, cloud.name, uuid);
115+
MaintenanceTarget target = new MaintenanceTarget(MaintenanceTarget.TargetType.CLOUD, cloud.name);
119116
MaintenanceAction action = new MaintenanceAction(target);
120117

121118
if (action.hasMaintenanceWindows()) {
@@ -348,34 +345,15 @@ public void doAdd(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException,
348345

349346
MaintenanceWindow maintenanceWindow = new MaintenanceWindow(startTime, endTime, reason);
350347

351-
for (String cloudParam : cloudParams) {
352-
String[] parts = cloudParam.split("::", 2);
353-
if (parts.length != 2) {
354-
LOGGER.log(Level.WARNING, "Invalid cloud parameter format: {0}", cloudParam);
355-
continue;
356-
}
357-
String cloudName = parts[0];
358-
String uuidStr = parts[1];
359-
String uuid = "null".equals(uuidStr) ? null : uuidStr;
360-
Cloud cloud = null;
361-
if (uuid == null) {
362-
cloud = j.getCloud(cloudName);
363-
} else {
364-
for (Cloud c : j.clouds) {
365-
if (c.name.equals(cloudName) && uuid.equals(CLOUD_UUID_STORE.getUuidIfPresent(c))) {
366-
cloud = c;
367-
break;
368-
}
369-
}
370-
}
371-
348+
for (String cloudName : cloudParams) {
349+
Cloud cloud = j.clouds.getByName(cloudName);
372350
if (cloud == null) {
373-
LOGGER.warning("Could not find cloud with name " + cloudName + " and UUID " + uuid);
351+
LOGGER.warning("Could not find cloud: " + cloudName);
374352
continue;
375353
}
376354

377355
try {
378-
MaintenanceTarget target = new MaintenanceTarget(MaintenanceTarget.TargetType.CLOUD, cloud.name, uuid);
356+
MaintenanceTarget target = new MaintenanceTarget(MaintenanceTarget.TargetType.CLOUD, cloud.name);
379357
MaintenanceHelper.getInstance().addMaintenanceWindow(target.toKey(), maintenanceWindow);
380358
} catch (Exception e) {
381359
LOGGER.log(Level.WARNING, "Error adding cloud maintenance window", e);
@@ -414,23 +392,6 @@ public void doAdd(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException,
414392
rsp.sendRedirect(".");
415393
}
416394

417-
/**
418-
* Helper class for cloud selection in the UI.
419-
*/
420-
public record CloudOption(String name, String uuid, String shortUuid, boolean hasDuplicate) {
421-
422-
public String getValue() {
423-
return name + "::" + (uuid == null ? "null" : uuid);
424-
}
425-
426-
public String getDisplayName() {
427-
if (hasDuplicate) {
428-
return name + " (" + shortUuid + ")";
429-
}
430-
return name;
431-
}
432-
}
433-
434395
public Class<MaintenanceWindow> getMaintenanceWindowClass() {
435396
return MaintenanceWindow.class;
436397
}

0 commit comments

Comments
 (0)