Skip to content

Commit af23b85

Browse files
authored
Merge pull request #2046 from zlamalp/service
Allow blocking of all services on facility and destination
2 parents b6bf993 + 1e80921 commit af23b85

File tree

12 files changed

+213
-37
lines changed

12 files changed

+213
-37
lines changed

perun-base/src/main/java/cz/metacentrum/perun/core/api/exceptions/ServiceAlreadyBannedException.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cz.metacentrum.perun.core.api.exceptions;
22

3+
import cz.metacentrum.perun.core.api.Destination;
34
import cz.metacentrum.perun.core.api.Facility;
45
import cz.metacentrum.perun.core.api.Service;
56

@@ -14,6 +15,7 @@ public class ServiceAlreadyBannedException extends PerunException {
1415

1516
private Service service;
1617
private Facility facility;
18+
private Destination destination;
1719

1820
public ServiceAlreadyBannedException(String message) {
1921
super(message);
@@ -33,6 +35,12 @@ public ServiceAlreadyBannedException(Service service, Facility facility) {
3335
this.facility = facility;
3436
}
3537

38+
public ServiceAlreadyBannedException(Service service, Destination destination) {
39+
this(service.toString() + " is already banned on " + destination.toString());
40+
this.service = service;
41+
this.destination = destination;
42+
}
43+
3644
public Service getService() {
3745
return service;
3846
}
@@ -41,4 +49,8 @@ public Facility getFacility() {
4149
return facility;
4250
}
4351

52+
public Destination getDestination() {
53+
return destination;
54+
}
55+
4456
}

perun-core/src/main/java/cz/metacentrum/perun/core/api/ServicesManager.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public interface ServicesManager {
172172
ServiceAttributes getHierarchicalData(PerunSession perunSession, Service service, Facility facility) throws InternalErrorException, FacilityNotExistsException, ServiceNotExistsException, PrivilegeException;
173173

174174
/**
175-
* Generates the list of attributes per each user and per each resource. Resources are filtered by service.
175+
* Generates the list of attributes per each user and per each resource. Resources are filtered by service.
176176
* Never return member or member-resource attribute.
177177
*
178178
* @param perunSession
@@ -292,11 +292,11 @@ public interface ServicesManager {
292292

293293
/**
294294
* Generates the list of attributes per each member associated with the resources and groups in vos.
295-
*
295+
*
296296
* @param perunSession
297297
* @param service attributes required by this service you will get
298298
* @param facility you will get attributes for this facility, vos associated with this facility by resources, resources associated with it and members assigned to the resources
299-
* @return attributes in special structure.
299+
* @return attributes in special structure.
300300
* Facility is in the root, facility children are vos.
301301
* Vo first child is abstract structure which children are resources.
302302
* Resource first child is abstract structure which children are groups.
@@ -305,8 +305,8 @@ public interface ServicesManager {
305305
* Group second chi is abstract structure which children are members.
306306
<pre>
307307
Facility
308-
+---Attrs
309-
+---ChildNodes
308+
+---Attrs
309+
+---ChildNodes
310310
+-----Vo
311311
| +---Attrs
312312
| +---ChildNodes
@@ -370,7 +370,7 @@ public interface ServicesManager {
370370
* @throws InternalErrorException
371371
* @throws FacilityNotExistsException
372372
* @throws ServiceNotExistsException
373-
* @throws PrivilegeException
373+
* @throws PrivilegeException
374374
* @throws VoNotExistsException
375375
*/
376376
ServiceAttributes getDataWithVos(PerunSession perunSession, Service service, Facility facility) throws InternalErrorException, VoNotExistsException, FacilityNotExistsException, ServiceNotExistsException, PrivilegeException;
@@ -756,8 +756,17 @@ public interface ServicesManager {
756756
*/
757757
void removeAllDestinations(PerunSession perunSession, Service service, Facility facility) throws PrivilegeException, InternalErrorException, ServiceNotExistsException, FacilityNotExistsException;
758758

759-
@Deprecated
760-
int getDestinationIdByName(PerunSession sess, String name) throws InternalErrorException, DestinationNotExistsException;
759+
/**
760+
* Return ID of Destination by its value (name) and type.
761+
*
762+
* @param sess
763+
* @param name Name (value) of Destination
764+
* @param type Type of destination
765+
* @return ID of Destination
766+
* @throws InternalErrorException
767+
* @throws DestinationNotExistsException
768+
*/
769+
int getDestinationIdByName(PerunSession sess, String name, String type) throws InternalErrorException, DestinationNotExistsException;
761770

762771
/**
763772
* List all services associated with the facility (via resource).

perun-core/src/main/java/cz/metacentrum/perun/core/bl/ServicesManagerBl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public interface ServicesManagerBl {
139139
* @param perunSession
140140
* @param service you will get attributes required by this service
141141
* @param facility you will get attributes for this facility, resources associated with it and users assigned to the resources
142-
* @return attributes in special structure. The facility is in the root. Facility first children is abstract node which contains no attributes and it's children are all resources.
142+
* @return attributes in special structure. The facility is in the root. Facility first children is abstract node which contains no attributes and it's children are all resources.
143143
* Facility second child is abstract node with no attribute and it's children are all users.
144144
*
145145
* @throws InternalErrorException
@@ -537,7 +537,17 @@ public interface ServicesManagerBl {
537537
*/
538538
void checkServicesPackageExists(PerunSession sess, ServicesPackage servicesPackage) throws InternalErrorException, ServicesPackageNotExistsException;
539539

540-
int getDestinationIdByName(PerunSession sess, String name) throws InternalErrorException, DestinationNotExistsException;
540+
/**
541+
* Returns Destinations ID based on destination name and type.
542+
*
543+
* @param sess
544+
* @param name Name (value) of destination
545+
* @param type type of destination
546+
* @return
547+
* @throws InternalErrorException
548+
* @throws DestinationNotExistsException
549+
*/
550+
int getDestinationIdByName(PerunSession sess, String name, String type) throws InternalErrorException, DestinationNotExistsException;
541551

542552
/**
543553
* List all services associated with the facility (via resource).

perun-core/src/main/java/cz/metacentrum/perun/core/blImpl/ServicesManagerBlImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,8 @@ public void checkServicesPackageExists(PerunSession sess, ServicesPackage servic
660660
}
661661

662662
@Override
663-
public int getDestinationIdByName(PerunSession sess, String name) throws InternalErrorException, DestinationNotExistsException {
664-
return servicesManagerImpl.getDestinationIdByName(sess, name);
663+
public int getDestinationIdByName(PerunSession sess, String name, String type) throws InternalErrorException, DestinationNotExistsException {
664+
return servicesManagerImpl.getDestination(sess, name, type).getId();
665665
}
666666

667667
@Override

perun-core/src/main/java/cz/metacentrum/perun/core/entry/ServicesManagerEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ public List<Destination> getFacilitiesDestinations(PerunSession sess, Vo vo) thr
676676
}
677677

678678
@Override
679-
public int getDestinationIdByName(PerunSession sess, String name) throws InternalErrorException, DestinationNotExistsException {
680-
return servicesManagerBl.getDestinationIdByName(sess, name);
679+
public int getDestinationIdByName(PerunSession sess, String name, String type) throws InternalErrorException, DestinationNotExistsException {
680+
return servicesManagerBl.getDestinationIdByName(sess, name, type);
681681
}
682682

683683
@Override

perun-core/src/main/java/cz/metacentrum/perun/core/impl/ServicesManagerImpl.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,6 @@ public Destination getDestinationById(PerunSession sess, int id) throws Internal
528528
}
529529
}
530530

531-
@Override
532-
@Deprecated
533-
public int getDestinationIdByName(PerunSession sess, String name) throws InternalErrorException, DestinationNotExistsException {
534-
try {
535-
return jdbc.queryForInt("select id from destinations where destination=?", name);
536-
} catch (EmptyResultDataAccessException e) {
537-
throw new DestinationNotExistsException(e);
538-
} catch (RuntimeException e) {
539-
throw new InternalErrorException(e);
540-
}
541-
}
542-
543531
@Override
544532
public void addDestination(PerunSession sess, Service service, Facility facility, Destination destination) throws InternalErrorException {
545533
try {

perun-core/src/main/java/cz/metacentrum/perun/core/implApi/ServicesManagerImplApi.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,6 @@ public interface ServicesManagerImplApi {
434434
*/
435435
void removeAllDestinations(PerunSession perunSession, Facility facility) throws InternalErrorException;
436436

437-
@Deprecated
438-
int getDestinationIdByName(PerunSession sess, String name) throws InternalErrorException, DestinationNotExistsException;
439-
440437
/**
441438
* Get destination by String destination and type
442439
*

perun-rpc/src/main/java/cz/metacentrum/perun/rpc/methods/GeneralServiceManagerMethod.java

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,58 @@ public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
3232
* @param service int Service <code>id</code>
3333
* @param destination int Destination <code>id</code>
3434
*/
35+
/*#
36+
* Bans Service on a destination.
37+
*
38+
* @param service int Service <code>id</code>
39+
* @param destinationName String Destination name (like hostnames)
40+
* @param destinationType String Destination type (like host, user@host, user@host:port, email, service-specific, ...)
41+
*/
3542
blockServiceOnDestination {
3643
public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
37-
ac.getGeneralServiceManager().blockServiceOnDestination(ac.getSession(), ac.getServiceById(parms.readInt("service")),parms.readInt("destination"));
44+
45+
if (parms.contains("destination")) {
46+
ac.getGeneralServiceManager().blockServiceOnDestination(ac.getSession(), ac.getServiceById(parms.readInt("service")),parms.readInt("destination"));
47+
} else {
48+
ac.getGeneralServiceManager().blockServiceOnDestination(ac.getSession(), ac.getServiceById(parms.readInt("service")), ac.getServicesManager().getDestinationIdByName(ac.getSession(), parms.readString("destinationName"), parms.readString("destinationType")));
49+
}
50+
return null;
51+
}
52+
},
53+
54+
/*#
55+
* Block all services currently assigned on this facility.
56+
* Newly assigned services are still allowed for propagation.
57+
*
58+
* @param facility int Facility <code>id</code>
59+
*/
60+
blockAllServicesOnFacility {
61+
public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
62+
ac.getGeneralServiceManager().blockAllServicesOnFacility(ac.getSession(), ac.getFacilityById(parms.readInt("facility")));
63+
return null;
64+
}
65+
},
66+
67+
/*#
68+
* Block all services currently assigned on this destination.
69+
* Newly assigned services are still allowed for propagation.
70+
*
71+
* @param destination int Destination <code>id</code>
72+
*/
73+
/*#
74+
* Block all services currently assigned on this destination.
75+
* Newly assigned services are still allowed for propagation.
76+
*
77+
* @param destinationName String Destination name (like hostnames)
78+
* @param destinationType String Destination type (like host, user@host, user@host:port, email, service-specific, ...)
79+
*/
80+
blockAllServicesOnDestination {
81+
public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
82+
if (parms.contains("destination")) {
83+
ac.getGeneralServiceManager().blockAllServicesOnDestination(ac.getSession(), parms.readInt("destination"));
84+
} else {
85+
ac.getGeneralServiceManager().blockAllServicesOnDestination(ac.getSession(), ac.getServicesManager().getDestinationIdByName(ac.getSession(), parms.readString("destinationName"), parms.readString("destinationType")));
86+
}
3887
return null;
3988
}
4089
},
@@ -114,9 +163,19 @@ public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
114163
*
115164
* @param destination int Destination <code>id</code>
116165
*/
166+
/*#
167+
* Erase all the possible denials on this destination.
168+
*
169+
* @param destinationName String Destination name (like hostnames)
170+
* @param destinationType String Destination type (like host, user@host, user@host:port, email, service-specific, ...)
171+
*/
117172
unblockAllServicesOnDestination {
118173
public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
119-
ac.getGeneralServiceManager().unblockAllServicesOnDestination(ac.getSession(), parms.readInt("destination"));
174+
if (parms.contains("destination")) {
175+
ac.getGeneralServiceManager().unblockAllServicesOnDestination(ac.getSession(), parms.readInt("destination"));
176+
} else {
177+
ac.getGeneralServiceManager().unblockAllServicesOnDestination(ac.getSession(), ac.getServicesManager().getDestinationIdByName(ac.getSession(), parms.readString("destinationName"), parms.readString("destinationType")));
178+
}
120179
return null;
121180
}
122181
},
@@ -145,9 +204,22 @@ public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
145204
* @param service int Service <code>id</code>
146205
* @param destination int Destination <code>id</code>
147206
*/
207+
/*#
208+
* Free the denial of the Service on this destination. If the Service was banned on
209+
* this destination, it will be freed. In case the Service was not banned on this
210+
* destination, nothing will happen.
211+
*
212+
* @param service int Service <code>id</code>
213+
* @param destinationName String Destination name (like hostnames)
214+
* @param destinationType String Destination type (like host, user@host, user@host:port, email, service-specific, ...)
215+
*/
148216
unblockServiceOnDestination {
149217
public Void call(ApiCaller ac, Deserializer parms) throws PerunException {
150-
ac.getGeneralServiceManager().unblockServiceOnDestination(ac.getSession(), ac.getServiceById(parms.readInt("service")),parms.readInt("destination"));
218+
if (parms.contains("destination")) {
219+
ac.getGeneralServiceManager().unblockServiceOnDestination(ac.getSession(), ac.getServiceById(parms.readInt("service")), parms.readInt("destination"));
220+
} else {
221+
ac.getGeneralServiceManager().unblockServiceOnDestination(ac.getSession(), ac.getServiceById(parms.readInt("service")), ac.getServicesManager().getDestinationIdByName(ac.getSession(), parms.readString("destinationName"), parms.readString("destinationType")));
222+
}
151223
return null;
152224
}
153225
},

perun-tasks-lib/src/main/java/cz/metacentrum/perun/controller/service/GeneralServiceManager.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cz.metacentrum.perun.core.api.Facility;
77
import cz.metacentrum.perun.core.api.PerunSession;
88
import cz.metacentrum.perun.core.api.Service;
9+
import cz.metacentrum.perun.core.api.exceptions.DestinationNotExistsException;
910
import cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException;
1011
import cz.metacentrum.perun.core.api.exceptions.InternalErrorException;
1112
import cz.metacentrum.perun.core.api.exceptions.PrivilegeException;
@@ -42,7 +43,31 @@ public interface GeneralServiceManager {
4243
* @param destinationId The destination on which we want to ban the Service
4344
* @throws InternalErrorException
4445
*/
45-
public void blockServiceOnDestination(PerunSession perunSession, Service service, int destinationId) throws InternalErrorException;
46+
public void blockServiceOnDestination(PerunSession perunSession, Service service, int destinationId) throws InternalErrorException, PrivilegeException, DestinationNotExistsException, ServiceAlreadyBannedException;
47+
48+
/**
49+
* Block all services currently assigned on this facility.
50+
* From this moment on, there are no Services being allowed on this facility.
51+
* If you assign a new service to the facility, it will be allowed!
52+
*
53+
* @param perunSession
54+
* @param facility Facility we want to block all services on.
55+
*
56+
* @throws InternalErrorException
57+
*/
58+
public void blockAllServicesOnFacility(PerunSession perunSession, Facility facility) throws InternalErrorException, FacilityNotExistsException, PrivilegeException;
59+
60+
/**
61+
* Block all services currently assigned on this destination.
62+
* From this moment on, there are no Services being allowed on this destination.
63+
* If you assign a new service to the destination, it will be allowed!
64+
*
65+
* @param perunSession
66+
* @param destinationId The id of a destination we want to block all services on.
67+
*
68+
* @throws InternalErrorException
69+
*/
70+
public void blockAllServicesOnDestination(PerunSession perunSession, int destinationId) throws InternalErrorException, PrivilegeException, DestinationNotExistsException;
4671

4772
/**
4873
* List all the Services that are banned on this facility.

0 commit comments

Comments
 (0)