Skip to content

Commit 9605505

Browse files
author
Marcus Sorensen
committed
CLOUDSTACK-6785: changed async job param injectedjobid to customjobid and check for unique/uuid
1 parent 2a5bf65 commit 9605505

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class ApiConstants {
6464
public static final String CUSTOMIZED = "customized";
6565
public static final String CUSTOMIZED_IOPS = "customizediops";
6666
public static final String CUSTOM_ID = "customid";
67+
public static final String CUSTOM_JOB_ID = "customjobid";
6768
public static final String MIN_IOPS = "miniops";
6869
public static final String MAX_IOPS = "maxiops";
6970
public static final String HYPERVISOR_SNAPSHOT_RESERVE = "hypervisorsnapshotreserve";

api/src/org/apache/cloudstack/api/BaseAsyncCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public abstract class BaseAsyncCmd extends BaseCmd {
3636
@Parameter(name = "starteventid", type = CommandType.LONG)
3737
private Long startEventId;
3838

39-
@Parameter(name= "injectedjobid", type = CommandType.STRING)
39+
@Parameter(name = ApiConstants.CUSTOM_JOB_ID , type = CommandType.STRING)
4040
private String injectedJobId;
4141

4242
public String getInjectedJobId() {

server/src/com/cloud/api/ApiServer.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
import com.cloud.utils.db.EntityManager;
169169
import com.cloud.utils.db.SearchCriteria;
170170
import com.cloud.utils.db.TransactionLegacy;
171+
import com.cloud.utils.db.UUIDManager;
171172
import com.cloud.utils.exception.CloudRuntimeException;
172173
import com.cloud.utils.exception.ExceptionProxyObject;
173174

@@ -195,7 +196,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
195196
private DomainManager _domainMgr;
196197
@Inject
197198
private DomainDao _domainDao;
198-
199+
@Inject
200+
private UUIDManager _uuidMgr;
199201
@Inject
200202
private AsyncJobManager _asyncMgr;
201203
@Inject
@@ -659,10 +661,15 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
659661
params.put("ctxDetails", ApiGsonHelper.getBuilder().create().toJson(ctx.getContextParameters()));
660662

661663
Long instanceId = (objectId == null) ? asyncCmd.getInstanceId() : objectId;
664+
665+
// users can provide the job id they want to use, so log as it is a uuid and is unique
666+
String injectedJobId = asyncCmd.getInjectedJobId();
667+
_uuidMgr.checkUuidSimple(injectedJobId, AsyncJob.class);
668+
662669
AsyncJobVO job = new AsyncJobVO("", callerUserId, caller.getId(), cmdObj.getClass().getName(),
663670
ApiGsonHelper.getBuilder().create().toJson(params), instanceId,
664671
asyncCmd.getInstanceType() != null ? asyncCmd.getInstanceType().toString() : null,
665-
asyncCmd.getInjectedJobId());
672+
injectedJobId);
666673
job.setDispatcher(_asyncDispatcher.getName());
667674

668675
final long jobId = _asyncMgr.submitAsyncJob(job);

server/src/com/cloud/uuididentity/UUIDManagerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ public <T> void checkUuid(String uuid, Class<T> entityType) {
5454
throw new PermissionDeniedException("Please check your permissions, you are not allowed to create/update custom id");
5555
}
5656

57+
checkUuidSimple(uuid, entityType);
58+
}
59+
60+
@Override
61+
public <T> void checkUuidSimple(String uuid, Class<T> entityType) {
62+
63+
if (uuid == null)
64+
return;
65+
5766
// check format
5867
if (!IsUuidFormat(uuid))
5968
throw new InvalidParameterValueException("UUID: " + uuid + " doesn't follow the UUID format");

utils/src/com/cloud/utils/db/UUIDManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ public interface UUIDManager {
3737
* .
3838
*/
3939
<T> void checkUuid(String uuid, Class<T> entityType);
40+
41+
/**
42+
* Checks the uuid for correct format, uniqueness, without checking permissions
43+
* @param uuid uuid to check
44+
* @param entityType the type of entity
45+
* .
46+
*/
47+
<T> void checkUuidSimple(String uuid, Class<T> entityType);
4048
}

0 commit comments

Comments
 (0)