Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-7052 [Community Contribution] Arquillian Remote Connector Make Address and Port Configurable #219

Merged
merged 8 commits into from
Apr 28, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2023 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fish.payara.arquillian.container.payara;

import java.util.Optional;

/**
* This interface abstracts getting details for a remote Payara instance configuration,
* which might override information retrieved from the instance via the admin API.
*/
public interface RemoteInstanceConnectionProvider {

Optional<String> getHttpHost();
Optional<Integer> getHttpPort();

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2021 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2017-2023 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -71,6 +71,7 @@

import fish.payara.arquillian.container.payara.CommonPayaraConfiguration;
import jakarta.ws.rs.ProcessingException;
import fish.payara.arquillian.container.payara.RemoteInstanceConnectionProvider;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext;
import org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
Expand Down Expand Up @@ -335,7 +336,21 @@ public HTTPContext doDeploy(String name, MultiPart form) {
Map<String, String> subComponents = (Map<String, String>) subComponentsResponse.get("properties");

// Build up the HTTPContext object using the nodeAddress information
HTTPContext httpContext = new HTTPContext(nodeAddress.getHost(), nodeAddress.getHttpPort());
String host = nodeAddress.getHost();
int port = nodeAddress.getHttpPort();
// If this configuration is for a remote instance, a user might want to override port and/or host
if (configuration instanceof RemoteInstanceConnectionProvider) {
RemoteInstanceConnectionProvider provider = (RemoteInstanceConnectionProvider) configuration;

if (provider.getHttpHost().isPresent()) {
host = provider.getHttpHost().get();
}
if (provider.getHttpPort().isPresent()) {
port = provider.getHttpPort().get();
}
}
HTTPContext httpContext = new HTTPContext(host, port);


// Add the servlets to the HTTPContext
String contextRoot = getApplicationContextRoot(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (c) 2017-2023 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fish.payara.arquillian.container.payara.remote;

import fish.payara.arquillian.container.payara.CommonPayaraConfiguration;
import fish.payara.arquillian.container.payara.RemoteInstanceConnectionProvider;
import org.jboss.arquillian.container.spi.ConfigurationException;

import java.util.Optional;

import static fish.payara.arquillian.container.payara.clientutils.PayaraClient.ADMINSERVER;
import static org.jboss.arquillian.container.spi.client.deployment.Validate.notNullOrEmpty;

/**
* Configuration for Remote Payara containers.
*
* @author <a href="http://community.jboss.org/people/dan.j.allen">Dan Allen</a>
* @author <a href="http://community.jboss.org/people/LightGuard">Jason Porter</a>
* @author Vineet Reynolds
*/
public class PayaraRemoteContainerConfiguration extends CommonPayaraConfiguration implements RemoteInstanceConnectionProvider {

private String httpHost;
private Integer httpPort;

public Optional<String> getHttpHost() {
return Optional.ofNullable(httpHost);
}

/**
* @param httpHost The hostname or ip address where the remote HTTP end can be reached
*/
public void setHttpHost(String httpHost) {
this.httpHost = httpHost;
}

public Optional<Integer> getHttpPort() {
return Optional.ofNullable(httpPort);
}

/**
* @param httpPort The port where the remote HTTP end can be reached
*/
public void setHttpPort(int httpPort) {
this.httpPort = httpPort;
}

@Override
public String getTarget() {
return ADMINSERVER;
}

/**
* Validates if current configuration is valid, that is if all required properties are set and
* have correct values
*/
@Override
public void validate() throws ConfigurationException {
if (httpPort != null && (httpPort < 0 || httpPort > 65535)) {
throw new IllegalArgumentException("The arquillian.xml property httpPort must be between 1 and 65535");
}

if (httpHost != null && httpHost.isEmpty()) {
throw new IllegalArgumentException("The arquillian.xml property httpHost must be not null or empty");
}

super.validate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
public class PayaraExtension implements LoadableExtension {
public class PayaraRemoteContainerExtension implements LoadableExtension {

@Override
public void register(ExtensionBuilder builder) {
builder.service(DeployableContainer.class, PayaraDeployableContainer.class);
builder.service(DeployableContainer.class, PayaraRemoteDeployableContainer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@
*
* @author <a href="http://community.jboss.org/people/LightGuard">Jason Porter</a>
*/
public class PayaraDeployableContainer implements DeployableContainer<CommonPayaraConfiguration> {
public class PayaraRemoteDeployableContainer implements DeployableContainer<PayaraRemoteContainerConfiguration> {

private CommonPayaraManager<CommonPayaraConfiguration> payaraManager;

public Class<CommonPayaraConfiguration> getConfigurationClass() {
return CommonPayaraConfiguration.class;
public Class<PayaraRemoteContainerConfiguration> getConfigurationClass() {
return PayaraRemoteContainerConfiguration.class;
}

public void setup(CommonPayaraConfiguration configuration) {
public void setup(PayaraRemoteContainerConfiguration configuration) {
if (configuration == null) {
throw new IllegalArgumentException("configuration must not be null");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fish.payara.arquillian.container.payara.remote.PayaraExtension
fish.payara.arquillian.container.payara.remote.PayaraRemoteContainerExtension