use of iaik.pkcs.pkcs11.Session in project open-kilda by telstra.
the class NeoDriver method getPath.
/**
* {@inheritDoc}
*/
@Override
public ImmutablePair<PathInfoData, PathInfoData> getPath(Flow flow, Strategy strategy) throws UnroutablePathException {
long latency = 0L;
List<PathNode> forwardNodes = new LinkedList<>();
List<PathNode> reverseNodes = new LinkedList<>();
if (!flow.isOneSwitchFlow()) {
Statement statement = getPathQuery(flow, strategy);
logger.debug("QUERY: {}", statement.toString());
try (Session session = driver.session()) {
StatementResult result = session.run(statement);
try {
Record record = result.next();
LinkedList<Relationship> isls = new LinkedList<>();
record.get(0).asPath().relationships().forEach(isls::add);
int seqId = 0;
for (Relationship isl : isls) {
latency += isl.get("latency").asLong();
forwardNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, isl.get("latency").asLong()));
seqId++;
forwardNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, 0L));
seqId++;
}
seqId = 0;
Collections.reverse(isls);
for (Relationship isl : isls) {
reverseNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, isl.get("latency").asLong()));
seqId++;
reverseNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, 0L));
seqId++;
}
} catch (NoSuchRecordException e) {
throw new UnroutablePathException(flow);
}
}
} else {
logger.info("No path computation for one-switch flow");
}
return new ImmutablePair<>(new PathInfoData(latency, forwardNodes), new PathInfoData(latency, reverseNodes));
}
use of iaik.pkcs.pkcs11.Session in project google-cloud-java by GoogleCloudPlatform.
the class SessionImplTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SpannerImpl spanner = new SpannerImpl(rpc, 1, null);
String dbName = "projects/p1/instances/i1/databases/d1";
String sessionName = dbName + "/sessions/s1";
DatabaseId db = DatabaseId.of(dbName);
Session sessionProto = Session.newBuilder().setName(sessionName).build();
Mockito.when(rpc.createSession(Mockito.eq(dbName), optionsCaptor.capture())).thenReturn(sessionProto);
session = spanner.createSession(db);
// We expect the same options, "options", on all calls on "session".
options = optionsCaptor.getValue();
Mockito.reset(rpc);
}
use of iaik.pkcs.pkcs11.Session in project cloudstack by apache.
the class ConfigTest method executeTest.
@Override
public boolean executeTest() {
int error = 0;
Element rootElement = this.getInputFile().get(0).getDocumentElement();
NodeList commandLst = rootElement.getElementsByTagName("command");
//Analyze each command, send request and build the array list of api commands
for (int i = 0; i < commandLst.getLength(); i++) {
Node fstNode = commandLst.item(i);
Element fstElmnt = (Element) fstNode;
//new command
ApiCommand api = new ApiCommand(fstElmnt, this.getParam(), this.getCommands());
if (api.getName().equals("rebootManagementServer")) {
s_logger.info("Attempting to SSH into management server " + this.getParam().get("hostip"));
try {
Connection conn = new Connection(this.getParam().get("hostip"));
conn.connect(null, 60000, 60000);
s_logger.info("SSHed successfully into management server " + this.getParam().get("hostip"));
boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
if (isAuthenticated == false) {
s_logger.info("Authentication failed for root with password");
return false;
}
String restartCommand = "service cloud-management restart; service cloud-usage restart";
Session sess = conn.openSession();
s_logger.info("Executing : " + restartCommand);
sess.execCommand(restartCommand);
Thread.sleep(120000);
sess.close();
conn.close();
} catch (Exception ex) {
s_logger.error(ex);
return false;
}
} else {
//send a command
api.sendCommand(this.getClient(), null);
//verify the response of the command
if ((api.getResponseType() == ResponseType.ERROR) && (api.getResponseCode() == 200) && (api.getTestCaseInfo() != null)) {
s_logger.error("Test case " + api.getTestCaseInfo() + "failed. Command that was supposed to fail, passed. The command was sent with the following url " + api.getUrl());
error++;
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() == 200)) {
//set parameters for the future use
if (api.setParam(this.getParam()) == false) {
s_logger.error("Exiting the test...Command " + api.getName() + " didn't return parameters needed for the future use. The command was sent with url " + api.getUrl());
return false;
} else {
//verify parameters
if (api.verifyParam() == false) {
s_logger.error("Command " + api.getName() + " failed. Verification for returned parameters failed. Command was sent with url " + api.getUrl());
error++;
} else if (api.getTestCaseInfo() != null) {
s_logger.info("Test case " + api.getTestCaseInfo() + " passed. Command was sent with the url " + api.getUrl());
}
}
} else if ((api.getResponseType() != ResponseType.ERROR) && (api.getResponseCode() != 200)) {
s_logger.error("Command " + api.getName() + " failed with an error code " + api.getResponseCode() + " . Command was sent with url " + api.getUrl() + " Required: " + api.getRequired());
if (api.getRequired() == true) {
s_logger.info("The command is required for the future use, so exiging");
return false;
}
error++;
} else if (api.getTestCaseInfo() != null) {
s_logger.info("Test case " + api.getTestCaseInfo() + " passed. Command that was supposed to fail, failed - test passed. Command was sent with url " + api.getUrl());
}
}
}
if (error != 0)
return false;
else
return true;
}
use of iaik.pkcs.pkcs11.Session in project Payara by payara.
the class SSHLauncher method runCommandAsIs.
private int runCommandAsIs(String command, OutputStream os, List<String> stdinLines, String[] env) throws IOException, InterruptedException {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Running command " + command + " on host: " + this.host);
}
openConnection();
StringBuffer buff = new StringBuffer();
if (env != null) {
Session tempSession = connection.openSession();
OutputStream ous = new ByteArrayOutputStream();
exec(tempSession, "ps -p $$ | tail -1 | awk '{print $NF}'", ous, null);
String prefix;
if (ous.toString().contains("csh")) {
logger.fine("CSH shell");
prefix = "setenv";
} else {
logger.fine("BASH shell");
prefix = "export";
}
for (String st : env) {
String cmd = prefix + " " + st;
buff.append(cmd).append(";");
}
}
buff.append(command);
final Session sess = connection.openSession();
int status = exec(sess, buff.toString(), os, listInputStream(stdinLines));
// XXX: Should we close connection after each command or cache it
// and re-use it?
SSHUtil.unregister(connection);
connection = null;
return status;
}
use of iaik.pkcs.pkcs11.Session in project wildfly-swarm by wildfly-swarm.
the class BMTStatefulTestBean method twoTransactions.
public String twoTransactions() throws Exception {
// start the JTA transaction via javax.transaction.UserTransaction
userTransaction.begin();
try {
// obtain session which will be enlisted into the JTA transaction.
Session session = driver.session();
if (session != driver.session()) {
throw new RuntimeException("multiple calls to Driver.session() must return the same session within JTA transaction.");
}
// Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
try {
Transaction transaction = session.beginTransaction();
fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
} catch (RuntimeException expectedException) {
// success
}
session.run("CREATE (a:Person {name:'BMT', title:'King'})");
// calls to close the session should also be ignored, since the session is also considered to be enlisted into the JTA transaction
session.close();
if (session.isOpen() != true) {
throw new RuntimeException("Session should be open since JTA transaction is still active.");
}
// commit the JTA transaction, which also calls org.neo4j.driver.v1.Transaction.success()/close().
// if the JTA transaction rolls back, org.neo4j.driver.v1.Transaction.failure()/close() would instead be called.
userTransaction.commit();
if (session.isOpen() != false) {
throw new RuntimeException("Session should now be closed since JTA transaction ended.");
}
// should be ignored
session.close();
// Start another JTA transaction, note that the session has to be obtained again
userTransaction.begin();
session = driver.session();
if (session != driver.session()) {
throw new RuntimeException("multiple calls to Driver.session() must return the same session within JTA transaction.");
}
// Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
try {
Transaction transaction = session.beginTransaction();
fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
} catch (RuntimeException expectedException) {
// success
}
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'BMT' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
if (userTransaction.getStatus() == Status.STATUS_ACTIVE) {
// second JTA transaction is ended, which also closes the enlisted org.neo4j.driver.v1.Transaction/Session
userTransaction.commit();
}
Session cleanupSession = driver.session();
cleanupSession.run("MATCH (a:Person) delete a");
cleanupSession.close();
}
}
Aggregations