mirror of https://github.com/apache/cloudstack.git
changes for access checks
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
ac25dc9fb9
commit
b52daa2be5
|
|
@ -101,7 +101,8 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long>, StateDao<State,
|
|||
|
||||
List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType);
|
||||
|
||||
List<NetworkVO> listByTrafficType(TrafficType trafficType, Filter filter);
|
||||
List<NetworkVO> listByTrafficTypeAndOwners(final TrafficType trafficType, List<Long> accountIds,
|
||||
List<Long> domainIds, Filter filter);
|
||||
|
||||
void setCheckForGc(long networkId);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import javax.persistence.TableGenerator;
|
|||
|
||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
|
|
@ -646,9 +647,22 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long>implements Ne
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkVO> listByTrafficType(final TrafficType trafficType, Filter filter) {
|
||||
final SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
|
||||
public List<NetworkVO> listByTrafficTypeAndOwners(final TrafficType trafficType, List<Long> accountIds,
|
||||
List<Long> domainIds, Filter filter) {
|
||||
SearchBuilder<NetworkVO> sb = createSearchBuilder();
|
||||
sb.and("trafficType", sb.entity().getTrafficType(), Op.EQ);
|
||||
sb.and().op("account", sb.entity().getAccountId(), Op.IN);
|
||||
sb.or("domain", sb.entity().getDomainId(), Op.IN);
|
||||
sb.cp();
|
||||
sb.done();
|
||||
final SearchCriteria<NetworkVO> sc = sb.create();
|
||||
sc.setParameters("trafficType", trafficType);
|
||||
if (CollectionUtils.isNotEmpty(accountIds)) {
|
||||
sc.setParameters("account", accountIds.toArray());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(domainIds)) {
|
||||
sc.setParameters("domain", domainIds);
|
||||
}
|
||||
|
||||
return listBy(sc, filter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,13 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
|
||||
import com.cloud.server.ResourceTag;
|
||||
import com.cloud.server.ResourceTag.ResourceObjectType;
|
||||
import com.cloud.tags.ResourceTagVO;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
|
||||
public interface ResourceTagDao extends GenericDao<ResourceTagVO, Long> {
|
||||
|
||||
|
|
@ -62,5 +63,6 @@ public interface ResourceTagDao extends GenericDao<ResourceTagVO, Long> {
|
|||
|
||||
List<? extends ResourceTag> listByResourceUuid(String resourceUuid);
|
||||
|
||||
List<ResourceTagVO> listByResourceType(ResourceObjectType resourceType, Filter filter);
|
||||
List<ResourceTagVO> listByResourceTypeAndOwners(ResourceObjectType resourceType, List<Long> accountIds,
|
||||
List<Long> domainIds, Filter filter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@
|
|||
// under the License.
|
||||
package com.cloud.tags.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.server.ResourceTag;
|
||||
|
|
@ -123,9 +124,22 @@ public class ResourceTagsDaoImpl extends GenericDaoBase<ResourceTagVO, Long> imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceTagVO> listByResourceType(ResourceObjectType resourceType, Filter filter) {
|
||||
SearchCriteria<ResourceTagVO> sc = AllFieldsSearch.create();
|
||||
public List<ResourceTagVO> listByResourceTypeAndOwners(ResourceObjectType resourceType, List<Long> accountIds,
|
||||
List<Long> domainIds, Filter filter) {
|
||||
SearchBuilder<ResourceTagVO> sb = createSearchBuilder();
|
||||
sb.and("resourceType", sb.entity().getResourceType(), Op.EQ);
|
||||
sb.and().op("account", sb.entity().getAccountId(), SearchCriteria.Op.IN);
|
||||
sb.or("domain", sb.entity().getDomainId(), SearchCriteria.Op.IN);
|
||||
sb.cp();
|
||||
sb.done();
|
||||
final SearchCriteria<ResourceTagVO> sc = sb.create();;
|
||||
sc.setParameters("resourceType", resourceType);
|
||||
if (CollectionUtils.isNotEmpty(accountIds)) {
|
||||
sc.setParameters("account", accountIds.toArray());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(domainIds)) {
|
||||
sc.setParameters("domain", domainIds);
|
||||
}
|
||||
return listBy(sc, filter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||
import org.apache.cloudstack.backup.ImageTransfer;
|
||||
import org.apache.cloudstack.backup.ImageTransferVO;
|
||||
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ImageTransferDao extends GenericDao<ImageTransferVO, Long> {
|
||||
|
|
@ -30,4 +31,5 @@ public interface ImageTransferDao extends GenericDao<ImageTransferVO, Long> {
|
|||
ImageTransferVO findByVolume(Long volumeId);
|
||||
ImageTransferVO findUnfinishedByVolume(Long volumeId);
|
||||
List<ImageTransferVO> listByPhaseAndDirection(ImageTransfer.Phase phase, ImageTransfer.Direction direction);
|
||||
List<ImageTransferVO> listByOwners(List<Long> accountIds, List<Long> domainIds, Filter filter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@ import javax.annotation.PostConstruct;
|
|||
|
||||
import org.apache.cloudstack.backup.ImageTransfer;
|
||||
import org.apache.cloudstack.backup.ImageTransferVO;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
|
@ -102,4 +104,22 @@ public class ImageTransferDaoImpl extends GenericDaoBase<ImageTransferVO, Long>
|
|||
sc.setParameters("direction", direction);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImageTransferVO> listByOwners(List<Long> accountIds, List<Long> domainIds, Filter filter) {
|
||||
SearchBuilder<ImageTransferVO> sb = createSearchBuilder();
|
||||
sb.and().op("account", sb.entity().getAccountId(), SearchCriteria.Op.IN);
|
||||
sb.or("domain", sb.entity().getDomainId(), SearchCriteria.Op.IN);
|
||||
sb.cp();
|
||||
sb.done();
|
||||
final SearchCriteria<ImageTransferVO> sc = sb.create();
|
||||
if (CollectionUtils.isNotEmpty(accountIds)) {
|
||||
sc.setParameters("account", accountIds.toArray());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(domainIds)) {
|
||||
sc.setParameters("domain", domainIds);
|
||||
}
|
||||
|
||||
return listBy(sc, filter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.veeam.adapter;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface ApiAccess {
|
||||
Class<? extends BaseCmd> command();
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.veeam.adapter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public class ApiAccessInterceptor implements MethodInterceptor {
|
||||
@Inject
|
||||
AccountManager accountManager;
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Method m = invocation.getMethod();
|
||||
Object target = invocation.getThis();
|
||||
if (target == null) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
ApiAccess access = m.getAnnotation(ApiAccess.class);
|
||||
if (access == null) {
|
||||
m = target.getClass().getMethod(m.getName(), m.getParameterTypes());
|
||||
access = m.getAnnotation(ApiAccess.class);
|
||||
}
|
||||
if (access == null) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
ServerAdapter adapter = (ServerAdapter) target;
|
||||
Pair<User, Account> serviceUserAccount = adapter.getServiceAccount();
|
||||
String apiName = BaseCmd.getCommandNameByClass(access.command());
|
||||
|
||||
accountManager.checkApiAccess(serviceUserAccount.second(), apiName);
|
||||
|
||||
CallContext.register(serviceUserAccount.first(), serviceUserAccount.second());
|
||||
try {
|
||||
return invocation.proceed();
|
||||
} finally {
|
||||
CallContext.unregister();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -39,6 +39,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class DataCentersRouteHandler extends ManagerBase implements RouteHandler {
|
||||
public static final String BASE_ROUTE = "/api/datacenters";
|
||||
|
|
@ -111,6 +112,8 @@ public class DataCentersRouteHandler extends ManagerBase implements RouteHandler
|
|||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (InvalidParameterValueException e) {
|
||||
io.notFound(resp, e.getMessage(), outFormat);
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,10 +121,14 @@ public class DisksRouteHandler extends ManagerBase implements RouteHandler {
|
|||
|
||||
protected void handleGet(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
Negotiation.OutFormat outFormat, VeeamControlServlet io) throws IOException {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<Disk> result = serverAdapter.listAllDisks(query.getOffset(), query.getLimit());
|
||||
NamedList<Disk> response = NamedList.of("disk", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
try {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<Disk> result = serverAdapter.listAllDisks(query.getOffset(), query.getLimit());
|
||||
NamedList<Disk> response = NamedList.of("disk", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handlePost(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
|
|
@ -161,15 +165,7 @@ public class DisksRouteHandler extends ManagerBase implements RouteHandler {
|
|||
|
||||
protected void handlePutById(final String id, final HttpServletRequest req, final HttpServletResponse resp,
|
||||
final Negotiation.OutFormat outFormat, final VeeamControlServlet io) throws IOException {
|
||||
String data = RouteHandler.getRequestData(req, logger);
|
||||
try {
|
||||
// ToDo: do what?
|
||||
// serverAdapter.deleteDisk(id);
|
||||
Disk response = serverAdapter.getDisk(id);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (InvalidParameterValueException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
throw new InvalidParameterValueException("Put Disk with ID " + id + " not implemented");
|
||||
}
|
||||
|
||||
protected void handlePostDiskCopy(final String id, final HttpServletRequest req, final HttpServletResponse resp,
|
||||
|
|
|
|||
|
|
@ -106,10 +106,14 @@ public class ImageTransfersRouteHandler extends ManagerBase implements RouteHand
|
|||
|
||||
protected void handleGet(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
Negotiation.OutFormat outFormat, VeeamControlServlet io) throws IOException {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<ImageTransfer> result = serverAdapter.listAllImageTransfers(query.getOffset(), query.getLimit());
|
||||
NamedList<ImageTransfer> response = NamedList.of("image_transfer", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
try {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<ImageTransfer> result = serverAdapter.listAllImageTransfers(query.getOffset(), query.getLimit());
|
||||
NamedList<ImageTransfer> response = NamedList.of("image_transfer", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handlePost(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class JobsRouteHandler extends ManagerBase implements RouteHandler {
|
||||
public static final String BASE_ROUTE = "/api/jobs";
|
||||
|
|
@ -84,9 +85,13 @@ public class JobsRouteHandler extends ManagerBase implements RouteHandler {
|
|||
|
||||
protected void handleGet(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
Negotiation.OutFormat outFormat, VeeamControlServlet io) throws IOException {
|
||||
final List<Job> result = serverAdapter.listPendingJobs();
|
||||
NamedList<Job> response = NamedList.of("job", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
try {
|
||||
final List<Job> result = serverAdapter.listPendingJobs();
|
||||
NamedList<Job> response = NamedList.of("job", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleGetById(final String id, final HttpServletResponse resp, final Negotiation.OutFormat outFormat,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class NetworksRouteHandler extends ManagerBase implements RouteHandler {
|
||||
public static final String BASE_ROUTE = "/api/networks";
|
||||
|
|
@ -85,10 +86,14 @@ public class NetworksRouteHandler extends ManagerBase implements RouteHandler {
|
|||
|
||||
protected void handleGet(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
Negotiation.OutFormat outFormat, VeeamControlServlet io) throws IOException {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<Network> result = serverAdapter.listAllNetworks(query.getOffset(), query.getLimit());
|
||||
NamedList<Network> response = NamedList.of("network", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
try {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<Network> result = serverAdapter.listAllNetworks(query.getOffset(), query.getLimit());
|
||||
NamedList<Network> response = NamedList.of("network", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleGetById(final String id, final HttpServletResponse resp, final Negotiation.OutFormat outFormat,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class TagsRouteHandler extends ManagerBase implements RouteHandler {
|
||||
public static final String BASE_ROUTE = "/api/tags";
|
||||
|
|
@ -86,10 +87,14 @@ public class TagsRouteHandler extends ManagerBase implements RouteHandler {
|
|||
|
||||
protected void handleGet(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
Negotiation.OutFormat outFormat, VeeamControlServlet io) throws IOException {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<Tag> result = serverAdapter.listAllTags(query.getOffset(), query.getLimit());
|
||||
NamedList<Tag> response = NamedList.of("tag", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
try {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<Tag> result = serverAdapter.listAllTags(query.getOffset(), query.getLimit());
|
||||
NamedList<Tag> response = NamedList.of("tag", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleGetById(final String id, final HttpServletResponse resp, final Negotiation.OutFormat outFormat,
|
||||
|
|
|
|||
|
|
@ -231,10 +231,14 @@ public class VmsRouteHandler extends ManagerBase implements RouteHandler {
|
|||
|
||||
protected void handleGet(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
Negotiation.OutFormat outFormat, VeeamControlServlet io) throws IOException {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<Vm> result = serverAdapter.listAllInstances(query.getOffset(), query.getLimit());
|
||||
NamedList<Vm> response = NamedList.of("vm", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
try {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<Vm> result = serverAdapter.listAllInstances(query.getOffset(), query.getLimit());
|
||||
NamedList<Vm> response = NamedList.of("vm", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handlePost(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
|
|
@ -308,7 +312,6 @@ public class VmsRouteHandler extends ManagerBase implements RouteHandler {
|
|||
protected void handleStopVmById(final String id, final HttpServletRequest req, final HttpServletResponse resp,
|
||||
final Negotiation.OutFormat outFormat, final VeeamControlServlet io) throws IOException {
|
||||
boolean async = isRequestAsync(req);
|
||||
String data = RouteHandler.getRequestData(req, logger);
|
||||
try {
|
||||
VmAction vm = serverAdapter.stopInstance(id, async);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_ACCEPTED, vm, outFormat);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class VnicProfilesRouteHandler extends ManagerBase implements RouteHandler {
|
||||
public static final String BASE_ROUTE = "/api/vnicprofiles";
|
||||
|
|
@ -85,10 +86,14 @@ public class VnicProfilesRouteHandler extends ManagerBase implements RouteHandle
|
|||
|
||||
protected void handleGet(final HttpServletRequest req, final HttpServletResponse resp,
|
||||
Negotiation.OutFormat outFormat, VeeamControlServlet io) throws IOException {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<VnicProfile> result = serverAdapter.listAllVnicProfiles(query.getOffset(), query.getLimit());
|
||||
NamedList<VnicProfile> response = NamedList.of("vnic_profile", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
try {
|
||||
ListQuery query = ListQuery.fromRequest(req);
|
||||
final List<VnicProfile> result = serverAdapter.listAllVnicProfiles(query.getOffset(), query.getLimit());
|
||||
NamedList<VnicProfile> response = NamedList.of("vnic_profile", result);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, response, outFormat);
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleGetById(final String id, final HttpServletResponse resp, final Negotiation.OutFormat outFormat,
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@
|
|||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop.xsd"
|
||||
>
|
||||
|
||||
<bean id="routeHandlerRegistry"
|
||||
|
|
@ -50,5 +53,14 @@
|
|||
</bean>
|
||||
|
||||
<bean id="serverAdapter" class="org.apache.cloudstack.veeam.adapter.ServerAdapter"/>
|
||||
<bean id="apiAccessInterceptor" class="org.apache.cloudstack.veeam.adapter.ApiAccessInterceptor"/>
|
||||
|
||||
<!--
|
||||
AOP
|
||||
-->
|
||||
<aop:config proxy-target-class="true">
|
||||
<aop:advisor advice-ref="apiAccessInterceptor"
|
||||
pointcut="execution(public * org.apache.cloudstack.veeam.adapter.ServerAdapter.*(..)) && @annotation(org.apache.cloudstack.veeam.adapter.ApiAccess)" />
|
||||
</aop:config>
|
||||
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import com.cloud.storage.ScopeType;
|
|||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
|
||||
import com.cloud.api.query.vo.StoragePoolJoinVO;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
|
@ -45,6 +46,6 @@ public interface StoragePoolJoinDao extends GenericDao<StoragePoolJoinVO, Long>
|
|||
|
||||
List<StoragePoolVO> findStoragePoolByScopeAndRuleTags(Long datacenterId, Long podId, Long clusterId, ScopeType scopeType, List<String> tags);
|
||||
|
||||
List<StoragePoolJoinVO> listByZoneAndProvider(long zoneId, Filter filter);
|
||||
List<StoragePoolJoinVO> listByZoneAndType(long zoneId, List<Storage.StoragePoolType> types, Filter filter);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
|
|||
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
|
|
@ -412,12 +413,16 @@ public class StoragePoolJoinDaoImpl extends GenericDaoBase<StoragePoolJoinVO, Lo
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<StoragePoolJoinVO> listByZoneAndProvider(long zoneId, Filter filter) {
|
||||
public List<StoragePoolJoinVO> listByZoneAndType(long zoneId, List<Storage.StoragePoolType> types, Filter filter) {
|
||||
SearchBuilder<StoragePoolJoinVO> sb = createSearchBuilder();
|
||||
sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||
sb.and("types", sb.entity().getZoneId(), SearchCriteria.Op.IN);
|
||||
sb.done();
|
||||
SearchCriteria<StoragePoolJoinVO> sc = sb.create();
|
||||
sc.setParameters("zoneId", zoneId);
|
||||
if (CollectionUtils.isNotEmpty(types)) {
|
||||
sc.setParameters("types", types.toArray());
|
||||
}
|
||||
return listBy(sc, filter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,5 +52,6 @@ public interface UserVmJoinDao extends GenericDao<UserVmJoinVO, Long> {
|
|||
|
||||
List<UserVmJoinVO> listLeaseInstancesExpiringInDays(int days);
|
||||
|
||||
List<UserVmJoinVO> listByHypervisorType(Hypervisor.HypervisorType hypervisorType, Filter filter);
|
||||
List<UserVmJoinVO> listByHypervisorTypeAndOwners(Hypervisor.HypervisorType hypervisorType, List<Long> accountIds,
|
||||
String domainPath, Filter filter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,13 @@
|
|||
package com.cloud.api.query.dao;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
|
@ -34,9 +33,6 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.gpu.dao.VgpuProfileDao;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupResponse;
|
||||
import org.apache.cloudstack.annotation.AnnotationService;
|
||||
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
||||
|
|
@ -62,11 +58,14 @@ import com.cloud.api.ApiDBUtils;
|
|||
import com.cloud.api.ApiResponseHelper;
|
||||
import com.cloud.api.query.vo.UserVmJoinVO;
|
||||
import com.cloud.gpu.GPU;
|
||||
import com.cloud.gpu.dao.VgpuProfileDao;
|
||||
import com.cloud.host.ControlState;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.vpc.VpcVO;
|
||||
import com.cloud.network.vpc.dao.VpcDao;
|
||||
import com.cloud.service.ServiceOfferingDetailsVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
|
|
@ -96,7 +95,6 @@ import com.cloud.vm.VirtualMachine.State;
|
|||
import com.cloud.vm.VmStats;
|
||||
import com.cloud.vm.dao.NicExtraDhcpOptionDao;
|
||||
import com.cloud.vm.dao.NicSecondaryIpVO;
|
||||
|
||||
import com.cloud.vm.dao.VMInstanceDetailsDao;
|
||||
|
||||
@Component
|
||||
|
|
@ -836,12 +834,22 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<UserVmJoinVO> listByHypervisorType(Hypervisor.HypervisorType hypervisorType, Filter filter) {
|
||||
public List<UserVmJoinVO> listByHypervisorTypeAndOwners(Hypervisor.HypervisorType hypervisorType,
|
||||
List<Long> accountIds, String domainPath, Filter filter) {
|
||||
SearchBuilder<UserVmJoinVO> sb = createSearchBuilder();
|
||||
sb.and("hypervisorType", sb.entity().getHypervisorType(), Op.EQ);
|
||||
sb.and().op("account", sb.entity().getAccountId(), Op.IN);
|
||||
sb.or("domainPath", sb.entity().getDomainPath(), Op.LIKE);
|
||||
sb.cp();
|
||||
sb.done();
|
||||
SearchCriteria<UserVmJoinVO> sc = sb.create();
|
||||
sc.setParameters("hypervisorType", hypervisorType);
|
||||
if (CollectionUtils.isNotEmpty(accountIds)) {
|
||||
sc.setParameters("account", accountIds.toArray());
|
||||
}
|
||||
if (StringUtils.isNotBlank(domainPath)) {
|
||||
sc.setParameters("domainPath", domainPath + "%");
|
||||
}
|
||||
return listBy(sc, filter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,5 +39,6 @@ public interface VolumeJoinDao extends GenericDao<VolumeJoinVO, Long> {
|
|||
|
||||
List<VolumeJoinVO> listByInstanceId(long instanceId);
|
||||
|
||||
List<VolumeJoinVO> listByHypervisor(Hypervisor.HypervisorType hypervisorType, Filter filter);
|
||||
List<VolumeJoinVO> listByHypervisorTypeAndOwners(Hypervisor.HypervisorType hypervisorType, List<Long> accountIds,
|
||||
String domainPath, Filter filter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ import java.util.List;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import org.apache.cloudstack.annotation.AnnotationService;
|
||||
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
|
|
@ -31,11 +29,15 @@ import org.apache.cloudstack.context.CallContext;
|
|||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.ApiResponseHelper;
|
||||
import com.cloud.api.query.vo.VolumeJoinVO;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
|
|
@ -382,14 +384,24 @@ public class VolumeJoinDaoImpl extends GenericDaoBaseWithTagInformation<VolumeJo
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeJoinVO> listByHypervisor(Hypervisor.HypervisorType hypervisorType, Filter filter) {
|
||||
public List<VolumeJoinVO> listByHypervisorTypeAndOwners(Hypervisor.HypervisorType hypervisorType,
|
||||
List<Long> accountIds, String domainPath, Filter filter) {
|
||||
SearchBuilder<VolumeJoinVO> sb = createSearchBuilder();
|
||||
sb.and("vmType", sb.entity().getVmType(), SearchCriteria.Op.EQ);
|
||||
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
|
||||
sb.and().op("account", sb.entity().getAccountId(), SearchCriteria.Op.IN);
|
||||
sb.or("domainPath", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE);
|
||||
sb.cp();
|
||||
sb.done();
|
||||
SearchCriteria<VolumeJoinVO> sc = sb.create();
|
||||
sc.setParameters("vmType", VirtualMachine.Type.User);
|
||||
sc.setParameters("hypervisorType", hypervisorType);
|
||||
if (CollectionUtils.isNotEmpty(accountIds)) {
|
||||
sc.setParameters("account", accountIds.toArray());
|
||||
}
|
||||
if (StringUtils.isNotBlank(domainPath)) {
|
||||
sc.setParameters("domainPath", domainPath + "%");
|
||||
}
|
||||
return search(sc, filter);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import javax.persistence.Convert;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
|
@ -40,6 +41,10 @@ import org.apache.cloudstack.util.HypervisorTypeConverter;
|
|||
@Table(name = "volume_view")
|
||||
public class VolumeJoinVO extends BaseViewWithTagInformationVO implements ControlledViewEntity {
|
||||
|
||||
@Id
|
||||
@Column(name = "id", updatable = false, nullable = false)
|
||||
private long id;
|
||||
|
||||
@Column(name = "uuid")
|
||||
private String uuid;
|
||||
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager, C
|
|||
return _projectAccountDao.persist(projectAccountVO);
|
||||
}
|
||||
|
||||
public ProjectAccount assignUserToProject(Project project, long userId, long accountId, Role userRole, Long projectRoleId) {
|
||||
public ProjectAccount assignUserToProject(Project project, long userId, long accountId, Role userRole, Long projectRoleId) {
|
||||
return assignAccountToProject(project, accountId, userRole, userId, projectRoleId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -172,7 +172,8 @@ public class MockNetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkVO> listByTrafficType(final TrafficType trafficType, Filter filter) {
|
||||
public List<NetworkVO> listByTrafficTypeAndOwners(final TrafficType trafficType, List<Long> accountIds,
|
||||
List<Long> domainIds, Filter filter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue