I am trying to use the Wildfly 9 native management API to show me the status of my deployed apps. The jboss-cli execution and result is below:
jboss-cli.sh --connect --controller=myserver.com:9990 --commands="/deployment=my-deployment.war :read-attribute(name=status)"
{
"outcome" => "success",
"result" => "OK"
}
Using the code below, I am able to determine if the apps are enabled, but not if they are up and running:
ModelNode op = new ModelNode();
op.get("operation").set("read-children-names");
op.get("child-type").set(ClientConstants.DEPLOYMENT);
Can anyone assist in translating my jboss-cli commands into Java? I've tried hooking into the deployment-scanner subsystem as well, but that doesn't seem to get me anywhere useful.
This answer from a similar thread worked for us (with some minor tweaking): https://stackoverflow.com/a/41261864/3486967
You can use the read-children-resource operation to get the deployment resources.
Something like the following should work.
try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
ServerHelper.waitForStandalone(client, 20L);
final ModelNode op = Operations.createOperation("read-children-resources");
op.get(ClientConstants.CHILD_TYPE).set(ClientConstants.DEPLOYMENT);
final ModelNode result = client.execute(op);
if (Operations.isSuccessfulOutcome(result)) {
final List<Property> deployments = Operations.readResult(result).asPropertyList();
for (Property deployment : deployments) {
System.out.printf("Deployment %-20s enabled? %s%n", deployment.getName(), deployment.getValue().get("enabled"));
}
} else {
throw new RuntimeException(Operations.getFailureDescription(result).asString());
}
}
Related
I have an Azure Java Function App (Java 11, gradle, azure-functions-java-library 1.4.0) that is tied to an event hub trigger. There are parameters that I can inject into the annotation by surrounding with % as per https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns. The connection isn't using the % since it's a special param that is always taken from the app properties.
When I run my function locally, using ./gradlew azureFunctionsRun it runs as expected. But once it's deployed to an Azure Function App, it complains that it can't resolve the params.
The error in Azure:
2021-05-27T18:25:37.522 [Error] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.EventHubTrigger'. Microsoft.Azure.WebJobs.Host: '%app.eventhub.name%' does not resolve to a value.
The Trigger annotation looks like:
#FunctionName("EventHubTrigger")
public void run(
#EventHubTrigger(name = "event",
connection = "app.eventhub.connectionString",
eventHubName = "%app.eventhub.name%",
consumerGroup = "%app.eventhub.consumerGroup%",
cardinality = Cardinality.MANY)
List<Event> event,
final ExecutionContext context
) {
// logic
}
Locally in local.settings.json I have values for:
"app.eventhub.connectionString": "Endpoint=XXXX",
"app.eventhub.name": "hubName",
"app.eventhub.consumerGroup": "consumerName"
And in Azure for the function app, I have Configuration (under Settings) for each of the above.
Any ideas what I'm missing?
After some further investigation, I managed to get things working in Azure Function Apps by changing my naming convention, from using . as separators to _.
This ended up working both locally and when deployed:
#FunctionName("EventHubTrigger")
public void run(
#EventHubTrigger(name = "event",
connection = "app_eventhub_connectionString",
eventHubName = "%app_eventhub_name%",
consumerGroup = "%app_eventhub_consumerGroup%",
cardinality = Cardinality.MANY)
List<Event> event,
final ExecutionContext context
) {
// logic
}
With configuration settings in local.settings.json as:
"app_eventhub_connectionString": "Endpoint=XXXX",
"app_eventhub_name": "hubName",
"app_eventhub_consumerGroup": "consumerName"
And corresponding updates made to the App configuration.
I am unable to enable and configure flow log for network security group, using a storage account in either the NetworkWatcherRG or another existing resource group. I am wondering what I am doing wrong from the sdk, as I can do so from the azure gui easily.
To Reproduce
retrieve network watchers
for network watcher in correct region
retrieve flow settings for existing network security group in the region
update flow settings to enable logging and set storage to existing storage account
final PagedList<NetworkWatcher> nws = adapter.getItsAzure().networkWatchers().list();
NetworkWatcher retval = null;
for(final NetworkWatcher nw : nws ) {
if(nw.region().equals(Region.GOV_US_VIRGINIA)) {
retval = nw;
}
}
final ResourceGroup rg = adapter.getItsAzure().resourceGroups().getByName(retval.resourceGroupName());
final StorageAccount sa = adapter.getItsAzure().storageAccounts().define(ResourceNameType.STORAGE_ACCOUNT.randomName("networkwatchersa"))
.withRegion(Region.GOV_US_VIRGINIA)
.withExistingResourceGroup(rg)
.withAccessFromAllNetworks()
.create();
final String rgName = "resource-group-38f6628eccb84ec9aa1cd9b3c8f5f815";
final NetworkSecurityGroup nsg = adapter.getItsAzure().networkSecurityGroups().getByResourceGroup(rgName, "add-network1-nat-securitygroup");
final FlowLogSettings fls = retval.getFlowLogSettings(nsg.id());
LOGGER.info("Found fls with enabled {} and storage id {}", fls.enabled(), fls.storageId());
fls.update()
.withLogging()
.withStorageAccount(sa.id())
.apply();
The client has permission to perform action 'Microsoft.OperationalInsights/workspaces/sharedKeys/action' on scope '/subscriptions/{subscription_id}/resourceGroups/NetworkWatcherRG/providers/Microsoft.Network/networkWatchers/NetworkWatcher_usgovvirginia', however the linked subscription 'resourcegroups' was not found
Note: subscription id was present in the above error, it has just been redacted for posting
Expected behavior
Expect to be able to enable flow logs for the nsg in a storage account, or a more elaborate error message, I cannot currently determine what the issue is
Setup:
OS: macOS
IDE : Eclipse Version: 2019-06 (4.12.0)
Version of the Library used: 1.23
Additional context
Call has been attempted with the Service Principal as both a contributor and owner in the subscription. I am trying to understand the error message as the sdk call seems straight forward. I suspect it is a permissions or ownership issue.
I have reproduced this issue from my side. And finally i have worked it out. Just ignore the misleading error message you got.
You need to provide TrafficAnalyticsConfigurationProperties to the FlowLogSettings, even if you do not want to turn it on.
So, you need to create a log analytic workspace first.
And you can refer the following code to enable and configure flow log for NSG.
NetworkWatcher nw = azure.networkWatchers().listByResourceGroup("NetworkWatcherRG").get(1);
NetworkSecurityGroup nsg = azure.networkSecurityGroups().getByResourceGroup("", "");
StorageAccount sa = azure.storageAccounts().getByResourceGroup("", "");
FlowLogSettings settings = nw.getFlowLogSettings(nsg.id());
TrafficAnalyticsConfigurationProperties networkWatcherFlowAnalyticsConfiguration = new TrafficAnalyticsConfigurationProperties();
networkWatcherFlowAnalyticsConfiguration.withWorkspaceId("").withWorkspaceRegion(Region.ASIA_SOUTHEAST.toString()).withWorkspaceResourceId("").withEnabled(false);
settings.inner().flowAnalyticsConfiguration()
.withNetworkWatcherFlowAnalyticsConfiguration(networkWatcherFlowAnalyticsConfiguration);
settings.update().withLogging().withRetentionPolicyEnabled().withRetentionPolicyDays(30).withStorageAccount(sa.id()).apply();
tl;dr: how can I get I/O when sending an exec command using sshj? Alternatively, what other Java SSH libraries provide a similar level of abstraction but might work better for my use case?
Apart from not working for me, yet, I really like sshj’s level of abstraction, most other Java/SSH libs are much lower level and I neither want nor need this for my use case.
Details:
As part for a tool for developer onboarding, I’m trying to install ssh
public keys on a gitblit server, patterned after
https://github.com/hierynomus/sshj/blob/master/examples/src/main/java/net/schmizz/sshj/examples/Exec.java.
I’m working with sshj:
compile 'com.hierynomus:sshj:0.21.1'
Platform: Koltin 1.1.3-2 (JRE 1.8.0_131-b11, Azul Zulu on Mac 10.12)
Unfortunately I can’t seem to read from or write to the streams.
I cut it down to this in the Repl, now just trying to get gitblits help message:
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.logging.Level
import java.util.logging.LogManager
fun sshClientWithTrustingHostkeyVerifier(): SSHClient {
return SSHClient(DefaultConfig()).also { client ->
client.addHostKeyVerifier(object :
OpenSSHKnownHosts(File(sshDir(), "known_hosts")) {
override fun hostKeyUnverifiableAction(hostname: String?, key: PublicKey?): Boolean {
super.write(SimpleEntry(null, hostname, KeyType.fromKey(key), key))
return true
}
})
}
}
LogManager.getLogManager().let {lm ->
lm.loggerNames.asSequence().forEach { lm.getLogger(it).apply{
level = Level.FINEST
handlers.forEach { it.level = Level.FINEST }}}}
val log: Logger = LoggerFactory.getLogger("foo")
log.debug("a")
val client = sshClientWithTrustingHostkeyVerifier()
log.debug("b")
client.connect("the.gitblit.local", 29418)
log.debug("c")
client.authPassword("my_account", "my super password")
log.debug("d")
val session = client.startSession()
log.debug("e")
val cmd = session.exec("keys --help")
log.debug("f")
log.debug(cmd.inputStream.readBytes().toString())
log.debug("g")
log.debug(cmd.errorStream.readBytes().toString())
log.debug("h")
cmd.join()
log.debug("i")
log.debug("Exit status: {}", cmd.exitStatus)
This produces a lot of output, which includes a strange-sounding error
"[PROTOCOL_ERROR] Received CHANNEL_SUCCESS". I posted the full output on https://pastebin.com/d3Y1tc8r.
If I then let it sit, after a while it dies of a timeout. No output ever materializes.
I am executing My Jobs/ Transformation using Java API and I am able to do it correctly in my host.
Now I am looking for a way to execute the transformation in remote host(where carte in running). Please help me or redirect me to the proper documentation where I find the classes to use to accomplish this.
PDI Version - 5.0.1
Currently I am executing my Job as below
try {
if(jobDetails.getGraphlocation()!=null)
{
KettleEnvironment.init();
JobMeta jobMeta = new JobMeta(jobDetails.getGraphlocation(), null);
for( String s : jobDetails.getArguments() )
{
String[] splitString = s.split("\\=");
if(splitString.length==2)
{
jobMeta.setParameterValue(splitString[0], splitString[1]);
}
else
System.err.println("Parameter should be of the form - name=value");
}
Job job = new Job(null, jobMeta);
job.setLogLevel(LogLevel.valueOf(jobDetails.getLoglevel().toString()));
job.start();
job.waitUntilFinished();
if (job.getErrors()!=0) {
System.out.println("Error encountered!");
}
}
The above code is able to execute the Job where ever I am running it. But I want to execute it in slave server by just passing the carte username,password ans server IP address.
you can do it through spoon by registering the carte server, or you can do it in a job by specifying the name and port of the carte server in the actual job/transformation step. i.e. you can create a launcher which just has start, job ( pointing at carte server ), success steps.
I have a grails app, and I am using the java-apns 0.1.5 jar! I have a device key, which already uninstall my app from it, so my question is, should I receive same feedback from the API saying that device is not enable anymore?
My code is the following:
apnsService = APNS.newService()
.withCert(pathToCertificate, password)
.withFeedbackDestination("feedback.sandbox.push.apple.com",2196)
.withSandboxDestination()
.build();
apnsService.start();
Map<String, Date> inactiveDevices = apnsService.getInactiveDevices();
log.debug inactiveDevices
.....
the think is that, the variable inactiveDevices is always empty! why? if I uninstall the app from the device?! am I missing some think in the client(device) side?
If you are using the Sandbox destination, the feedback service may not
report info correctly. This is a known bug with a known workaround,
check the mailing list thread
The problem comes from the "Sandbox" APNs Feedback server, probably a
bug. Here is the solution if anyone has the same problem:
Create a dummy app id in the program portal, enable development push
notifications on it Create and download the associated provisioning
profile Create a new xcode project, and invoke the
registerForRemoteNotificationTypes method on start. Install the dummy
app on your device. At this point, you should have two DEVELOPMENT
apps running on your device: the original app and the dummy app. Both
should be registered to receive push notifications. Uninstall the
original app, and try to send a push notification to that app. Invoke
the feedback service, and you should receive data back.
To resume, the Sandbox Feedbacks server needs TWO DEVELOPMENT Apps
registered on the SAME iPhone to work. This manipulation is not
necessary for the production phase as the "Production" APNs Feedback
server works fine.
I would recommend just switching to test feedback with the production servers.
Please either test with the production servers or use the workaround.
Hello Guys i have done push using grails APNS also with simple java lib.
1. With Grails : here is code snippet for APNS using grails
Hello Guys i have done push using grails APNS.
there are one Important point to remember
1. Proper apple certificate, Apple approved.: Apple approve certificate after 24 hours.
here is my code
1. in config.groovy
environments {
development {
apns {
pathToCertificate = "/Users/sarbogast/Desktop/APNs_development_certificates.p12"
password = "password"
environment = "sandbox"
}
} test {
apns {
pathToCertificate = "/usr/local/myapp/APNs_development_certificates.p12"
password = "password"
environment = "sandbox"
}
} production {
apns {
pathToCertificate = "/usr/local/myapp/APNs_production_certificates.p12"
password = "password"
environment = "production"
}
}
}2. i create a service and here is my service class code def sendMessageToDevices() { List<string> aa = new ArrayList<string>() aa.add("Testing") def payload = APNS.newPayload() .badge(1) .localizedKey("key") .localizedArguments(aa) .sound("default") log.error(payload.length()) if (payload.isTooLong()){ log.info("Message is too long: " + payload.length()) } try { apnsService.testConnection() apnsService.push("Device token here", payload.build() ) } catch (Exception e) { log.error("Could not connect to APNs to send the notification"+e.getMessage()) } }
here "key" is any message which will popup on device push
3. i called this method by controller method..