use of com.redhat.jenkins.plugins.ci.provider.data.RabbitMQPublisherProviderData in project jms-messaging-plugin by jenkinsci.
the class RabbitMQMessagingPluginIntegrationTest method testFedoraMessagingHeaders.
@Test
public void testFedoraMessagingHeaders() throws Exception {
FreeStyleProject job = j.createFreeStyleProject();
job.getPublishersList().add(new CIMessageNotifier(new RabbitMQPublisherProviderData("test", null, "", true, true, 20, "schema")));
FreeStyleBuild lastBuild = j.buildAndAssertSuccess(job);
j.assertLogContains("fedora_messaging_severity=20, fedora_messaging_schema=schema}", lastBuild);
j.assertLogContains("{sent_at=", lastBuild);
}
use of com.redhat.jenkins.plugins.ci.provider.data.RabbitMQPublisherProviderData in project jms-messaging-plugin by jenkinsci.
the class RabbitMQMessagingWorker method sendMessage.
@Override
public SendResult sendMessage(Run<?, ?> build, TaskListener listener, ProviderData pdata) {
RabbitMQPublisherProviderData pd = (RabbitMQPublisherProviderData) pdata;
try {
if (connection == null || !connection.isOpen()) {
connect();
}
if (channel == null || !channel.isOpen()) {
this.channel = connection.createChannel();
log.info("Channel created.");
}
} catch (Exception ex) {
ex.printStackTrace();
}
String body = "";
String msgId = "";
// Fedora messaging wire format support
Map<String, Object> headers = new HashMap<>();
if (pd.isFedoraMessaging()) {
headers.put("fedora_messaging_severity", pd.getSeverity());
headers.put("fedora_messaging_schema", pd.getSchema());
headers.put("sent_at", ZonedDateTime.now().toString());
}
System.out.println(headers);
try {
EnvVars env = new EnvVars();
env.putAll(build.getEnvironment(listener));
env.put("CI_NAME", build.getParent().getName());
if (!build.isBuilding()) {
env.put("CI_STATUS", (build.getResult() == Result.SUCCESS ? "passed" : "failed"));
env.put("BUILD_STATUS", build.getResult().toString());
}
RabbitMQMessage msg = new RabbitMQMessage(PluginUtils.getSubstitutedValue(getTopic(provider), build.getEnvironment(listener)), PluginUtils.getSubstitutedValue(pd.getMessageContent(), env));
msg.setTimestamp(System.currentTimeMillis() / 1000L);
body = msg.getBodyJson();
msgId = msg.getMsgId();
try {
channel.exchangeDeclarePassive(exchangeName);
channel.basicPublish(exchangeName, msg.getTopic(), new AMQP.BasicProperties.Builder().headers(headers).messageId(msgId).build(), body.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
if (pd.isFailOnError()) {
log.severe("Unhandled exception in perform: Failed to send message!");
return new SendResult(false, msgId, body);
}
}
log.fine("Message headers:\n" + headers);
log.fine("JSON message:\n" + msg.toJson());
listener.getLogger().println("Message id: " + msg.getMsgId());
listener.getLogger().println("Message topic: " + msg.getTopic());
listener.getLogger().println("Message headers:\n" + headers);
listener.getLogger().println("JSON message body:\n" + body);
} catch (Exception e) {
if (pd.isFailOnError()) {
log.severe("Unhandled exception in perform: ");
log.severe(ExceptionUtils.getStackTrace(e));
listener.fatalError("Unhandled exception in perform: ");
listener.fatalError(ExceptionUtils.getStackTrace(e));
return new SendResult(false, msgId, body);
} else {
log.warning("Unhandled exception in perform: ");
log.warning(ExceptionUtils.getStackTrace(e));
listener.error("Unhandled exception in perform: ");
listener.error(ExceptionUtils.getStackTrace(e));
return new SendResult(true, msgId, body);
}
} finally {
try {
channel.close();
} catch (Exception e) {
log.warning("Unhandled exception when closing channel: ");
log.warning(ExceptionUtils.getStackTrace(e));
listener.getLogger().println("exception in finally");
}
}
return new SendResult(true, msgId, body);
}
use of com.redhat.jenkins.plugins.ci.provider.data.RabbitMQPublisherProviderData in project jms-messaging-plugin by jenkinsci.
the class MessageProviderMigrator method updateCIMessageBuilder.
private static boolean updateCIMessageBuilder(AbstractProject<?, ?> p, CIMessageBuilder builder) {
if (builder.getProviderData() == null) {
if (builder.getProviderName() == null) {
builder.setProviderName(GlobalCIConfiguration.get().getConfigs().get(0).getName());
}
JMSMessagingProvider prov = GlobalCIConfiguration.get().getProvider(builder.getProviderName());
if (prov instanceof ActiveMqMessagingProvider) {
ActiveMQPublisherProviderData apd = new ActiveMQPublisherProviderData(builder.getProviderName());
apd.setOverrides(builder.getOverrides());
apd.setMessageType(builder.getMessageType());
apd.setMessageProperties(builder.getMessageProperties());
apd.setMessageContent(builder.getMessageContent());
apd.setFailOnError(builder.isFailOnError());
builder.setProviderData(apd);
} else if (prov instanceof FedMsgMessagingProvider) {
FedMsgPublisherProviderData fpd = new FedMsgPublisherProviderData(builder.getProviderName());
fpd.setOverrides(builder.getOverrides());
fpd.setMessageContent(builder.getMessageContent());
fpd.setFailOnError(builder.isFailOnError());
builder.setProviderData(fpd);
} else {
RabbitMQPublisherProviderData rpd = new RabbitMQPublisherProviderData(builder.getProviderName());
rpd.setOverrides(builder.getOverrides());
rpd.setMessageContent(builder.getMessageContent());
rpd.setFailOnError(builder.isFailOnError());
builder.setProviderData(rpd);
}
try {
p.save();
return true;
} catch (IOException e) {
log.log(Level.WARNING, "Failed to save project", e);
}
}
return false;
}
use of com.redhat.jenkins.plugins.ci.provider.data.RabbitMQPublisherProviderData in project jms-messaging-plugin by jenkinsci.
the class MessageProviderMigrator method updateCIMessageNotifier.
private static boolean updateCIMessageNotifier(AbstractProject<?, ?> p, CIMessageNotifier builder) {
if (builder.getProviderData() == null) {
if (builder.getProviderName() == null) {
builder.setProviderName(GlobalCIConfiguration.get().getConfigs().get(0).getName());
}
JMSMessagingProvider prov = GlobalCIConfiguration.get().getProvider(builder.getProviderName());
if (prov instanceof ActiveMqMessagingProvider) {
ActiveMQPublisherProviderData apd = new ActiveMQPublisherProviderData(builder.getProviderName());
apd.setOverrides(builder.getOverrides());
apd.setMessageType(builder.getMessageType());
apd.setMessageProperties(builder.getMessageProperties());
apd.setMessageContent(builder.getMessageContent());
apd.setFailOnError(builder.isFailOnError());
builder.setProviderData(apd);
} else if (prov instanceof FedMsgMessagingProvider) {
FedMsgPublisherProviderData fpd = new FedMsgPublisherProviderData(builder.getProviderName());
fpd.setOverrides(builder.getOverrides());
fpd.setMessageContent(builder.getMessageContent());
fpd.setFailOnError(builder.isFailOnError());
builder.setProviderData(fpd);
} else {
RabbitMQPublisherProviderData rpd = new RabbitMQPublisherProviderData(builder.getProviderName());
rpd.setOverrides(builder.getOverrides());
rpd.setMessageContent(builder.getMessageContent());
rpd.setFailOnError(builder.isFailOnError());
builder.setProviderData(rpd);
}
try {
p.save();
return true;
} catch (IOException e) {
log.log(Level.WARNING, "Failed to save project", e);
}
}
return false;
}
Aggregations