public String getMgmtAddress() { return NetworkUtils.formatPossibleIpv6Address(mgmtAddress); }
public JMXServiceURL getRemoteJMXURL() { try { switch (mgmtProtocol) { case "http-remoting": case "remote+http": return new JMXServiceURL("service:jmx:remote+http://" + NetworkUtils.formatPossibleIpv6Address(mgmtAddress) + ":" + mgmtPort); case "https-remoting": case "remote+https": return new JMXServiceURL("service:jmx:remote+https://" + NetworkUtils.formatPossibleIpv6Address(mgmtAddress) + ":" + mgmtPort); default: return new JMXServiceURL("service:jmx:remote://" + NetworkUtils.formatPossibleIpv6Address(mgmtAddress) + ":" + mgmtPort); } } catch (Exception e) { throw new RuntimeException("Could not create JMXServiceURL:" + this, e); } }
/** * Returns given URI with the replaced hostname. If the URI or host is null, then the original URI is returned. * * @param uri * @param host * @return * @throws java.net.URISyntaxException */ public static final URI replaceHost(final URI uri, final String host) throws URISyntaxException { final String origHost = uri == null ? null : uri.getHost(); final String newHost = NetworkUtils.formatPossibleIpv6Address(host); if (origHost == null || newHost == null || newHost.equals(origHost)) { return uri; } return new URI(uri.toString().replace(origHost, newHost)); }
/** * Returns "secondary.test.address" system property if such exists. If not found, then there is a fallback to * {@link ManagementClient#getMgmtAddress()}. Returned value is formatted to use in URLs (i.e. if it's IPv6 address, then * square brackets are placed around - e.g. "[::1]") * * @param mgmtClient management client instance (may be <code>null</code>) * @return */ public static String getSecondaryTestAddress(final ManagementClient mgmtClient) { return NetworkUtils.formatPossibleIpv6Address(getSecondaryTestAddress(mgmtClient, false)); }
@Override public void execute(ManagedServer server) throws Exception { assert Thread.holdsLock(ManagedServer.this); // Call under lock // Reconnect final String hostName = InetAddress.getByName(managementSocket.getHostName()).getHostName(); final int port = managementSocket.getPort(); processControllerClient.reconnectProcess(serverProcessName, NetworkUtils.formatPossibleIpv6Address(hostName), port, bootConfiguration.isManagementSubsystemEndpoint(), authKey); } }
/** * Converts socket address into string literal, which has form: 'address:port'. Example:<br> * <ul> * <li>127.0.0.1:8080</li> * <li>dns.name.com:8080</li> * <li>[0fe:1::20]:8080</li> * <li>[::1]:8080</li> * </ul> * @param inet * @return */ public static String formatAddress(InetSocketAddress inet){ if(inet == null){ throw new NullPointerException(); } StringBuilder result = new StringBuilder(); if(inet.isUnresolved()){ result.append(inet.getHostName()); }else{ result.append(formatPossibleIpv6Address(formatAddress(inet.getAddress()))); } result.append(":").append(inet.getPort()); return result.toString(); }
/** * Converts socket address into string literal, which has form: 'address:port'. Example:<br> * <ul> * <li>127.0.0.1:8080</li> * <li>dns.name.com:8080</li> * <li>[0fe:1::20]:8080</li> * <li>[::1]:8080</li> * </ul> * @param inet * @return */ public static String formatAddress(InetSocketAddress inet){ if(inet == null){ throw new NullPointerException(); } StringBuilder result = new StringBuilder(); if(inet.isUnresolved()){ result.append(inet.getHostName()); }else{ result.append(formatPossibleIpv6Address(formatAddress(inet.getAddress()))); } result.append(":").append(inet.getPort()); return result.toString(); }
private URI getBinding(final String protocol, final String socketBinding) { try { final String socketBindingGroupName = rootNode.get("socket-binding-group").keys().iterator().next(); final ModelNode operation = new ModelNode(); operation.get(OP_ADDR).get("socket-binding-group").set(socketBindingGroupName); operation.get(OP_ADDR).get("socket-binding").set(socketBinding); operation.get(OP).set(READ_RESOURCE_OPERATION); operation.get("include-runtime").set(true); ModelNode binding = executeForResult(operation); String ip = binding.get("bound-address").asString(); //it appears some system can return a binding with the zone specifier on the end if (ip.contains(":") && ip.contains("%")) { ip = ip.split("%")[0]; } final int port = defined(binding.get("bound-port"), socketBindingGroupName + " -> " + socketBinding + " -> bound-port is undefined").asInt(); return URI.create(protocol + "://" + NetworkUtils.formatPossibleIpv6Address(ip) + ":" + port); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Converts socket address into string literal, which has form: 'address:port'. Example:<br> * <ul> * <li>127.0.0.1:8080</li> * <li>dns.name.com:8080</li> * <li>[0fe:1::20]:8080</li> * <li>[::1]:8080</li> * </ul> * @param inet * @return */ public static String formatAddress(InetSocketAddress inet){ if(inet == null){ throw new NullPointerException(); } StringBuilder result = new StringBuilder(); if(inet.isUnresolved()){ result.append(inet.getHostName()); }else{ result.append(formatPossibleIpv6Address(formatAddress(inet.getAddress()))); } result.append(":").append(inet.getPort()); return result.toString(); }
public void reconnect(final String hostName, final int port, final byte[] authKey, final boolean mgmtSubsystemEndpoint) throws IOException, URISyntaxException { final String host = NetworkUtils.formatPossibleIpv6Address(hostName); final URI uri = new URI("remote://" + host + ":" + port); // In case the server is out of sync after the reconnect, set reload required final boolean mgmtEndpointChanged = this.managementSubsystemEndpoint != mgmtSubsystemEndpoint; if(! connection.reConnect(uri, authKey) || mgmtEndpointChanged) { // It would be nicer if we'd have direct access to the ControlledProcessState final ModelNode operation = new ModelNode(); operation.get(ModelDescriptionConstants.OP).set(ServerRestartRequiredHandler.OPERATION_NAME); // TODO only require reload operation.get(ModelDescriptionConstants.OP_ADDR).setEmptyList(); controller.execute(operation, OperationMessageHandler.DISCARD, ModelController.OperationTransactionControl.COMMIT, OperationAttachments.EMPTY); } } /**
public void reconnect(final String hostName, final int port, final byte[] authKey, final boolean mgmtSubsystemEndpoint) throws IOException, URISyntaxException { final String host = NetworkUtils.formatPossibleIpv6Address(hostName); final URI uri = new URI("remote://" + host + ":" + port); // In case the server is out of sync after the reconnect, set reload required final boolean mgmtEndpointChanged = this.managementSubsystemEndpoint != mgmtSubsystemEndpoint; if(! connection.reConnect(uri, authKey) || mgmtEndpointChanged) { // It would be nicer if we'd have direct access to the ControlledProcessState final ModelNode operation = new ModelNode(); operation.get(ModelDescriptionConstants.OP).set(ServerProcessStateHandler.REQUIRE_RELOAD_OPERATION); operation.get(ModelDescriptionConstants.OP_ADDR).setEmptyList(); controller.execute(operation, OperationMessageHandler.DISCARD, ModelController.OperationTransactionControl.COMMIT, OperationAttachments.EMPTY); } } /**
/** * Generates and returns the URI that corresponds to the remote outbound connection. * If the URI has already been generated in a previous request, then it returns that back. * Else the URI is constructed out of the outbound socket binding's destination address and destination port. * * @return * @throws IOException * @throws URISyntaxException */ private synchronized URI getConnectionURI() throws IOException, URISyntaxException { if (this.connectionURI != null) { return this.connectionURI; } final OutboundSocketBinding destinationOutboundSocket = this.destinationOutboundSocketBindingInjectedValue.getValue(); final InetAddress destinationAddress = destinationOutboundSocket.getDestinationAddress(); final int port = destinationOutboundSocket.getDestinationPort(); this.connectionURI = new URI(REMOTE_URI_SCHEME + NetworkUtils.formatPossibleIpv6Address( destinationAddress.getHostAddress()) + ":" + port); return this.connectionURI; }
private URL getConnectionURL() throws StartException { SocketBinding socketBinding = injectedHttpSocketBinding.getValue(); InetAddress address = socketBinding.getNetworkInterfaceBinding().getAddress(); URL result; try { String hostAddress = NetworkUtils.formatPossibleIpv6Address(address.getHostAddress()); result = new URL(socketBinding.getName() + "://" + hostAddress + ":" + socketBinding.getPort()); } catch (MalformedURLException ex) { throw new StartException(ex); } return result; }
public synchronized void doServiceDeploy(@Observes(precedence = 1) BeforeDeploy event, Container container, ServiceArchiveHolder archiveHolder) { // already deployed? if (serviceArchiveDeployed.contains(container.getName())) { archiveHolder.deploymentExistsAndRemove(event.getDeployment().getName()); // cleanup return; } // only deploy the service if the deployment has been enriched by the jmx-as7 protocol if (archiveHolder.deploymentExistsAndRemove(event.getDeployment().getName())) { JavaArchive serviceArchive = (JavaArchive) archiveHolder.getArchive(); try { log.infof("Deploy arquillian service: %s", serviceArchive); final Map<String, String> props = container.getContainerConfiguration().getContainerProperties(); //MASSIVE HACK //write the management connection props to the archive, so we can access them from the server final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bytes); out.writeObject(props.get("managementPort")); out.writeObject(NetworkUtils.formatPossibleIpv6Address(props.get("managementAddress"))); out.writeObject(NetworkUtils.formatPossibleIpv6Address(props.get("managementProtocol"))); out.writeObject(props.get("authenticationConfig")); out.close(); serviceArchive.addAsManifestResource(new ByteArrayAsset(bytes.toByteArray()), "org.jboss.as.managementConnectionProps"); DeployableContainer<?> deployableContainer = container.getDeployableContainer(); deployableContainer.deploy(serviceArchive); serviceArchiveDeployed.add(container.getName()); } catch (Throwable th) { log.error("Cannot deploy arquillian service", th); } } }
public synchronized void doServiceDeploy(@Observes(precedence = 1) BeforeDeploy event, Container container, ServiceArchiveHolder archiveHolder) { // already deployed? if (serviceArchiveDeployed.contains(container.getName())) { archiveHolder.deploymentExistsAndRemove(event.getDeployment().getName()); // cleanup return; } // only deploy the service if the deployment has been enriched by the jmx-as7 protocol if (archiveHolder.deploymentExistsAndRemove(event.getDeployment().getName())) { JavaArchive serviceArchive = (JavaArchive) archiveHolder.getArchive(); try { log.infof("Deploy arquillian service: %s", serviceArchive); final Map<String, String> props = container.getContainerConfiguration().getContainerProperties(); //MASSIVE HACK //write the management connection props to the archive, so we can access them from the server final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bytes); out.writeObject(props.get("managementPort")); out.writeObject(NetworkUtils.formatPossibleIpv6Address(props.get("managementAddress"))); out.writeObject(NetworkUtils.formatPossibleIpv6Address(props.get("managementProtocol"))); out.writeObject(props.get("authenticationConfig")); out.close(); serviceArchive.addAsManifestResource(new ByteArrayAsset(bytes.toByteArray()), "org.jboss.as.managementConnectionProps"); DeployableContainer<?> deployableContainer = container.getDeployableContainer(); deployableContainer.deploy(serviceArchive); serviceArchiveDeployed.add(container.getName()); } catch (Throwable th) { log.error("Cannot deploy arquillian service", th); } } }
protected void populateHostControllerInfo(LocalHostControllerInfoImpl hostControllerInfo, OperationContext context, ModelNode model) throws OperationFailedException { ModelNode hostNode = StaticDiscoveryResourceDefinition.HOST.resolveModelAttribute(context, model); ModelNode portNode = StaticDiscoveryResourceDefinition.PORT.resolveModelAttribute(context, model); ModelNode protocolNode = DomainControllerWriteAttributeHandler.PROTOCOL.resolveModelAttribute(context, model); String remoteDcHost = (!hostNode.isDefined()) ? null : NetworkUtils.formatPossibleIpv6Address(hostNode.asString()); int remoteDcPort = (!portNode.isDefined()) ? -1 : portNode.asInt(); String remoteDcProtocol = protocolNode.asString(); StaticDiscovery staticDiscoveryOption = new StaticDiscovery(remoteDcProtocol, remoteDcHost, remoteDcPort); hostControllerInfo.addRemoteDomainControllerDiscoveryOption(staticDiscoveryOption); } }
protected void populateHostControllerInfo(LocalHostControllerInfoImpl hostControllerInfo, OperationContext context, ModelNode model) throws OperationFailedException { ModelNode hostNode = StaticDiscoveryResourceDefinition.HOST.resolveModelAttribute(context, model); ModelNode portNode = StaticDiscoveryResourceDefinition.PORT.resolveModelAttribute(context, model); ModelNode protocolNode = DomainControllerWriteAttributeHandler.PROTOCOL.resolveModelAttribute(context, model); String remoteDcHost = (!hostNode.isDefined()) ? null : NetworkUtils.formatPossibleIpv6Address(hostNode.asString()); int remoteDcPort = (!portNode.isDefined()) ? -1 : portNode.asInt(); String remoteDcProtocol = protocolNode.asString(); StaticDiscovery staticDiscoveryOption = new StaticDiscovery(remoteDcProtocol, remoteDcHost, remoteDcPort); hostControllerInfo.addRemoteDomainControllerDiscoveryOption(staticDiscoveryOption); } }
FileUtils.deleteDirectory(WORK_DIR); WORK_DIR.mkdirs(); final String cannonicalHost = NetworkUtils.formatPossibleIpv6Address(Utils.getCannonicalHost(managementClient)); final Map<String, String> map = new HashMap<String, String>(); map.put("hostname", cannonicalHost);
public synchronized void doServiceDeploy(@Observes BeforeDeploy event, Container container, ServiceArchiveHolder archiveHolder) { // already deployed? if (serviceArchiveDeployed.contains(container.getName())) { archiveHolder.deploymentExistsAndRemove(event.getDeployment().getName()); // cleanup return; } // only deploy the service if the deployment has been enriched by the jmx-as7 protocol if (archiveHolder.deploymentExistsAndRemove(event.getDeployment().getName())) { JavaArchive serviceArchive = (JavaArchive) archiveHolder.getArchive(); try { log.infof("Deploy arquillian service: %s", serviceArchive); final Map<String, String> props = container.getContainerConfiguration().getContainerProperties(); //MASSIVE HACK //write the management connection props to the archive, so we can access them from the server final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bytes); out.writeObject(props.get("managementPort")); out.writeObject(NetworkUtils.formatPossibleIpv6Address(props.get("managementAddress"))); out.close(); serviceArchive.addAsManifestResource(new ByteArrayAsset(bytes.toByteArray()), "org.jboss.as.managementConnectionProps"); DeployableContainer<?> deployableContainer = container.getDeployableContainer(); deployableContainer.deploy(serviceArchive); serviceArchiveDeployed.add(container.getName()); } catch (Throwable th) { log.error("Cannot deploy arquillian service", th); } } }
final Endpoint endpoint = endpointInjector.getValue(); try { final URI connectionURI = new URI("remote://" + NetworkUtils.formatPossibleIpv6Address(hostName) + ":" + port); final OptionMap options = OptionMap.create(Options.SASL_DISALLOWED_MECHANISMS, Sequence.of(JBOSS_LOCAL_USER));