use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class NodeSource method buildRMNode.
/**
* Builds a RMNode from a raw Node
* @param node the node object
* @param provider the client of the request
* @return the expected RMNode
*/
private RMNode buildRMNode(Node node, Client provider) {
// creating a node access permission
// it could be either PROVIDER/PROVIDER_GROUPS and in this case
// the provider principals will be taken or
// ME/MY_GROUPS (ns creator/ns creator groups) and in this case
// creator's principals will be used
Client permissionOwner = administrator;
if (nodeUserAccessType.equals(AccessType.PROVIDER) || nodeUserAccessType.equals(AccessType.PROVIDER_GROUPS)) {
permissionOwner = provider;
}
// now selecting the type (user or group) and construct the permission
Set<IdentityPrincipal> principals = (Set<IdentityPrincipal>) nodeUserAccessType.getIdentityPrincipals(permissionOwner);
boolean tokenInNode = false;
boolean tokenInNodeSource = nodeUserAccessType.getTokens() != null && nodeUserAccessType.getTokens().length > 0;
try {
String nodeAccessToken = node.getProperty(RMNodeStarter.NODE_ACCESS_TOKEN);
tokenInNode = nodeAccessToken != null && nodeAccessToken.length() > 0;
if (tokenInNode) {
logger.debug("Node " + node.getNodeInformation().getURL() + " is protected by access token " + nodeAccessToken);
// it overrides all other principals
principals.clear();
principals.add(new TokenPrincipal(nodeAccessToken));
}
} catch (Exception e) {
throw new AddingNodesException(e);
}
PrincipalPermission nodeAccessPermission = new PrincipalPermission(node.getNodeInformation().getURL(), principals);
RMNodeImpl rmnode = new RMNodeImpl(node, stub, provider, nodeAccessPermission);
rmnode.setProtectedByToken(tokenInNode || tokenInNodeSource);
return rmnode;
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class ClientRequestHandler method addEvent.
/**
* Add an event to the request queue of this client
*
* @param method the method to be called (must be a method implemented by the client)
* @param args the argument to be passed to the method
*/
public void addEvent(Method method, Object... args) {
synchronized (eventCallsToStore) {
eventCallsToStore.add(new ReifiedMethodCall(method, args));
requestLeft.incrementAndGet();
}
tryStartTask();
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class SchedulerEventReceiver method openAndReceive.
@SuppressWarnings("rawtypes")
private void openAndReceive(final SchedulerEventListener eventListener, boolean myEventsOnly, SchedulerEvent... events) throws IOException {
Client client = ClientFactory.getDefault().newClient();
AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
if (insecure) {
builder = builder.setAcceptAnyCertificate(true).setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
AsyncHttpClientConfig httpClientConfig = builder.build();
AsyncHttpClient httpClient = new AsyncHttpClient(httpClientConfig);
socket = client.create(client.newOptionsBuilder().runtime(httpClient).reconnect(false).build());
EventNotificationHandler notificationHandler = new EventNotificationHandler(eventListener);
socket.on(Event.MESSAGE, notificationHandler);
socket.on(Event.CLOSE, new Function() {
public void on(Object t) {
SchedulerEventReceiver.logger.info("#### Websocket connection is closed ####");
if (eventListener instanceof DisconnectionAwareSchedulerEventListener) {
((DisconnectionAwareSchedulerEventListener) eventListener).notifyDisconnection();
}
}
});
// initialize the connection
RequestBuilder requestBuilder = client.newRequestBuilder();
requestBuilder.method(Request.METHOD.GET);
requestBuilder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
// authentication header
requestBuilder.header("sessionid", sessionId);
requestBuilder.uri(eventingUrl(restServerUrl));
requestBuilder.encoder(new EventSubscriptionEncoder());
requestBuilder.decoder(new EventNotificationDecoder());
requestBuilder.transport(Request.TRANSPORT.WEBSOCKET);
socket.open(requestBuilder.build());
// submit subscription request
EventSubscription eventSubscription = new EventSubscription(myEventsOnly, asStringArray(events));
socket.fire(EventCodecUtil.toJsonString(eventSubscription));
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class NodeSourceTest method setUp.
@Before
public void setUp() {
PAResourceManagerProperties.RM_TOPOLOGY_ENABLED.updateProperty("false");
infrastructureManager = mock(InfrastructureManager.class);
when(infrastructureManager.isUsingDeployingNode()).thenReturn(false);
NodeSourcePolicy nodeSourcePolicy = mock(NodeSourcePolicy.class);
when(nodeSourcePolicy.getProviderAccessType()).thenReturn(AccessType.ALL);
client = new Client(Subjects.create("user"), false);
nodeSource = createNodeSource(infrastructureManager, nodeSourcePolicy, client);
RMCore.topologyManager = new TopologyManager(HostsPinger.class);
}
use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.
the class SelectionManagerTest method testRunScriptsWillNotBeCalled.
@Test
public void testRunScriptsWillNotBeCalled() {
RMCore rmCore = newMockedRMCore(2);
SelectionManager selectionManager = createSelectionManager(rmCore);
Criteria crit = new Criteria(2);
crit.setTopology(TopologyDescriptor.SINGLE_HOST);
SelectionScript selectWhatever = new SelectionScript();
crit.setScripts(Lists.newArrayList(selectWhatever));
crit.setBlackList(null);
crit.setBestEffort(false);
Client mockedClient = mock(Client.class);
selectionManager.selectNodes(crit, mockedClient);
verify(rmCore, never()).setBusyNode(anyString(), any(Client.class));
}
Aggregations