Skip to content

Commit

Permalink
Fixing command helps, renaming dist bin file, setting build to offlin…
Browse files Browse the repository at this point in the history
…e mode
  • Loading branch information
malinthaprasan committed Jun 29, 2018
1 parent f50412c commit 2b92144
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Following is the structure of the label generated when running micro-gw setup co
```bash
micro-gw-<label>
├── bin (The binary scripts of the micro-gateway distribution)
│ └── micro-gw.sh
│ └── gateway
├── conf (micro gateway distribution configuration)
│ └── micro-gw.conf
├── exec (generated balx ballerina executable for the APIs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ private void validateAPIGetRequestParams(String label, String apiName, String ve
throw GatewayCmdUtils.createUsageException(
"Either label (-l <label>) or API name (-a <api-name>) with version (-v <version>) "
+ "should be provided."
+ "\n\nEx:\tmicro-gw setup -l accounts -n accounts-project"
+ "\n\tmicro-gw setup -a Pizzashack -v 1.0.0 -n pizzashack-project");
+ "\n\nEx:\tmicro-gw setup accounts-project -l accounts"
+ "\n\tmicro-gw setup pizzashack-project -a Pizzashack -v 1.0.0");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class GatewayCliConstants {
public static final String GW_DIST_FILTERS = "filters";
public static final String GW_DIST_RUNTIME = "runtime";
public static final String GW_DIST_EXEC = "exec";
public static final String GW_DIST_SH = "micro-gw.sh";
public static final String GW_DIST_SH = "gateway";
public static final String GW_DIST_SH_PATH = "distribution" + File.separator + GW_DIST_BIN + File.separator + GW_DIST_SH;
public static final String GW_DIST_EXTENSION_FILTER = "extension_filter.bal";
public static final String GW_DIST_CONF_FILE = "micro-gw.conf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.slf4j.LoggerFactory;
import org.wso2.apimgt.gateway.cli.constants.TokenManagementConstants;
import org.wso2.apimgt.gateway.cli.exception.CLIInternalException;
import org.wso2.apimgt.gateway.cli.exception.CLIRuntimeException;
import org.wso2.apimgt.gateway.cli.oauth.builder.DCRRequestBuilder;
import org.wso2.apimgt.gateway.cli.oauth.builder.OAuthTokenRequestBuilder;
import org.wso2.apimgt.gateway.cli.utils.TokenManagementUtil;
Expand All @@ -32,6 +33,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class OAuthServiceImpl implements OAuthService {
private static final Logger logger = LoggerFactory.getLogger(OAuthServiceImpl.class);
Expand Down Expand Up @@ -69,7 +71,11 @@ public String generateAccessToken(String tokenEndpoint, String username, char[]
throw new CLIInternalException("Error occurred while getting token. Status code: " + responseCode);
}
} catch (IOException e) {
throw new CLIInternalException("Error occurred while communicate with token endpoint " + tokenEndpoint, e);
String serverUrl = getServerUrl(tokenEndpoint);
throw new CLIRuntimeException(
"Error occurred while trying to connect with server. Is the server running at " + serverUrl + "?",
"Error occurred while trying to connect with token endpoint: " + tokenEndpoint, 1,
e);
} finally {
if (urlConn != null) {
urlConn.disconnect();
Expand Down Expand Up @@ -121,11 +127,21 @@ public String[] generateClientIdAndSecret(String dcrEndpoint, String username, c
"Error occurred while creating oAuth application Status code: " + responseCode);
}
} catch (IOException e) {
throw new CLIInternalException("Error occurred while communicate with DCR endpoint: " + dcrEndpoint, e);
String serverUrl = getServerUrl(dcrEndpoint);
throw new CLIRuntimeException(
"Error occurred while trying to connect with server. Is the server running at " + serverUrl + "?",
"Error occurred while communicate with DCR endpoint: " + dcrEndpoint, 1,
e);
} finally {
if (urlConn != null) {
urlConn.disconnect();
}
}
}

private String getServerUrl(String dcrEndpoint) {
String[] serverUrlParts = dcrEndpoint.split("/", 4);
return String.join("/",
Arrays.copyOfRange(serverUrlParts, 0, serverUrlParts.length >= 3 ? 3 : serverUrlParts.length));
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
NAME
micro-gw run - run command use to start services generated from the
from api definitions of given label. Using build command, it's generating the binary(balx)
sources of given label. Run command is used to start the services
micro-gw build - The build command generates a gateway distribution using the given project resources.

SYNOPSIS
micro-gw run [-l|--label] [args...]
micro-gw build <project>

DESCRIPTION
Run command executes services generated for the APIs specified for the given label

It's required run build command to compile a source and
provide the generated binary file (.balx file)

OPTIONS

--n <project-name>
--project <project-name>
Name of the project that should run the generated services from binary(balx) source

DEFAULT BEHAVIOR
Runs the services generated for given label
The build command generates a gateway distribution using the resources in the given project. The project should exist
in the current working directory and should be previously created using "micro-gw setup" command.

EXAMPLES
Run the services of given label
$ micro-gw build -l accounts
$ micro-gw build accounts-project

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ NAME
micro-gw help setup - set up the environment and generate the ballerina sources from the APIs of given label

SYNOPSIS
micro-gw setup [-u|--username] [-p|--password] [-l|--label]
[-o|--overwrite] [--path] [args...]
micro-gw setup <project> <[-l|--label] | [-a|--api-name] & [-v|--version]> [-u|--username] [-p|--password]
[-s|--server-url] [-c|--config] [-t|--trust-store] [-w|--truststore-pass]

DESCRIPTION
Setup command is used to create ballerina sources from api definition of given label. Setup command take username
Expand All @@ -15,19 +15,21 @@ OPTIONS

-l <label-name>
--label <label-name>
<Optional>
Name of the label which compile ballerina sources should be generated

-u
--username
<Optional>
Username of the user
-p
--password
<Optional>
Password of the user

--path
Path to the project location

-s
--server-url
<Optional>
APIM base url assuming all the portals are running in same node. By default base-url is https://localhost:9443/

-t
Expand All @@ -36,28 +38,31 @@ OPTIONS
Path to the trustStore file
By default consider <CLI_HOME>/lib/platform/bre/security/ballerinaTruststore.p12

-s
-w
--truststore-pass
<Optional>
Password for the given trustStore
By default use default trustStore password

-n
--project
<Optional>
Project name
If not present consider label as project name

-c
--config
<Optional>
Path to the cli configuration file
Be default use the <CLI_HOME>/resources/conf/cli-config.toml


DEFAULT BEHAVIOR
Generate the ballerina sources from given label along with the policies configured in the deployment

-a
--api-name
<Optional>
Name of the API

-v
--version
<Optional>
Version of the API

EXAMPLES
Setup the project
$ micro-gw.sh setup -l accounts --path /home/services
Setup the project using a label
$ micro-gw setup accounts-project -l accounts

Setup the project using a single API
$ micro-gw setup pizzashack-project -a PizzaShackAPI -v 1.0.0
2 changes: 1 addition & 1 deletion distribution/resources/bin/micro-gw
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if [ "$CMD_COMMAND" = "build" ] && [ "$CMD_PRO_NAME_VAL" != "" ] && [ "$MICRO_GW
rm -rf $MICRO_GW_LABEL_PROJECT_DIR/target
fi
# build the ballerina source code for the label
ballerina build src/ -o $CMD_PRO_NAME_VAL.balx
ballerina build src/ -o $CMD_PRO_NAME_VAL.balx --offline
popd > /dev/null
fi

Expand Down

0 comments on commit 2b92144

Please sign in to comment.