use of io.cdap.cdap.client.config.ClientConfig in project cdap by caskdata.
the class UpgradeJobMain method main.
public static void main(String[] args) {
if (args.length != 2) {
throw new RuntimeException(String.format("Invalid number of arguments to UpgradeJobMain. Needed 2, found %d", args.length));
}
// TODO(CDAP-18299): Refactor to use internal service discovery mechanism instead of making calls via the router.
ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(args[0]).setPort(Integer.parseInt(args[1])).setSSLEnabled(false).build();
ClientConfig.Builder clientConfigBuilder = ClientConfig.builder().setDefaultReadTimeout(DEFAULT_READ_TIMEOUT_MILLIS).setConnectionConfig(connectionConfig);
// If used in proxy mode, attach a user ID header to upgrade jobs.
CConfiguration cConf = CConfiguration.create();
if (SecurityUtil.isProxySecurity(cConf)) {
String proxyUserID = cConf.get(Constants.Security.Authentication.PROXY_USER_ID_HEADER);
if (proxyUserID == null) {
throw new RuntimeException("Invalid proxy user ID header");
}
clientConfigBuilder.addAdditionalHeader(proxyUserID, UpgradeUserIDProvider.getUserID());
}
ClientConfig clientConfig = clientConfigBuilder.build();
RetryStrategy retryStrategy = RetryStrategies.timeLimit(120, TimeUnit.SECONDS, RetryStrategies.exponentialDelay(500, 5000, TimeUnit.MILLISECONDS));
try {
Retries.callWithRetries(() -> {
suspendSchedulesAndStopPipelines(clientConfig);
return null;
}, retryStrategy, e -> e instanceof IOException || e instanceof NotFoundException);
} catch (Exception e) {
throw new RuntimeException("Failed to prepare instance for upgrade.", e);
}
}
use of io.cdap.cdap.client.config.ClientConfig in project cdap by caskdata.
the class UpgradeJobMain method suspendSchedulesAndStopPipelines.
private static void suspendSchedulesAndStopPipelines(ClientConfig clientConfig) throws Exception {
ApplicationClient applicationClient = new ApplicationClient(clientConfig);
ScheduleClient scheduleClient = new ScheduleClient(clientConfig);
ProgramClient programClient = new ProgramClient(clientConfig);
NamespaceClient namespaceClient = new NamespaceClient(clientConfig);
boolean shouldRetry = false;
List<NamespaceId> namespaceIdList = namespaceClient.list().stream().map(NamespaceMeta::getNamespaceId).collect(Collectors.toList());
namespaceIdList.add(NamespaceId.SYSTEM);
for (NamespaceId namespaceId : namespaceIdList) {
for (ApplicationRecord record : applicationClient.list(namespaceId)) {
ApplicationId applicationId = new ApplicationId(namespaceId.getNamespace(), record.getName(), record.getAppVersion());
LOG.debug("Trying to stop schedule and workflows for application " + applicationId);
List<WorkflowId> workflowIds = applicationClient.get(applicationId).getPrograms().stream().filter(programRecord -> programRecord.getType().equals(ProgramType.WORKFLOW)).map(programRecord -> new WorkflowId(applicationId, programRecord.getName())).collect(Collectors.toList());
for (WorkflowId workflowId : workflowIds) {
List<ScheduleId> scheduleIds = scheduleClient.listSchedules(workflowId).stream().map(scheduleDetail -> new ScheduleId(namespaceId.getNamespace(), record.getName(), record.getAppVersion(), scheduleDetail.getName())).collect(Collectors.toList());
for (ScheduleId scheduleId : scheduleIds) {
if (scheduleClient.getStatus(scheduleId).equals(SCHEDULED)) {
scheduleClient.suspend(scheduleId);
}
}
// Need to stop workflows first or else the program will fail to stop below
if (!programClient.getStatus(workflowId).equals(ProgramStatus.STOPPED.toString())) {
try {
programClient.stop(workflowId);
} catch (BadRequestException e) {
// transitioned to stop state since it was checked earlier or not.
if (!programClient.getStatus(workflowId).equals(ProgramStatus.STOPPED.toString())) {
// Pipeline still in running state. Continue with stopping rest of the pipelines in this namespace and
// next retry should try to stop/verify status for this pipeline.
shouldRetry = true;
}
}
}
}
}
// At least one pipeline is still in running state so retry to verify pipeline status .
if (shouldRetry) {
throw new RetryableException("At least one pipeline in namespace " + namespaceId + " is still running.");
}
// All schedules are stopped, now stop all programs
programClient.stopAll(namespaceId);
}
}
use of io.cdap.cdap.client.config.ClientConfig in project cdap by caskdata.
the class ArtifactHttpHandlerTestBase method setup.
@BeforeClass
public static void setup() {
artifactRepository = getInjector().getInstance(ArtifactRepository.class);
systemArtifactsDir = getInjector().getInstance(CConfiguration.class).get(Constants.AppFabric.SYSTEM_ARTIFACTS_DIR);
DiscoveryServiceClient discoveryClient = getInjector().getInstance(DiscoveryServiceClient.class);
EndpointStrategy endpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(Constants.Service.METADATA_SERVICE));
Discoverable discoverable = endpointStrategy.pick(1, TimeUnit.SECONDS);
Assert.assertNotNull(discoverable);
String host = discoverable.getSocketAddress().getHostName();
int port = discoverable.getSocketAddress().getPort();
ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(host).setPort(port).setSSLEnabled(URIScheme.HTTPS.isMatch(discoverable)).build();
ClientConfig clientConfig = ClientConfig.builder().setVerifySSLCert(false).setConnectionConfig(connectionConfig).build();
}
use of io.cdap.cdap.client.config.ClientConfig in project cdap by caskdata.
the class CLITestBase method createCLIConfig.
public static CLIConfig createCLIConfig(URI standaloneUri) throws Exception {
ConnectionConfig connectionConfig = InstanceURIParser.DEFAULT.parse(standaloneUri.toString());
ClientConfig clientConfig = new ClientConfig.Builder().setConnectionConfig(connectionConfig).build();
clientConfig.setAllTimeouts(60000);
return new CLIConfig(clientConfig, System.out, new CsvTableRenderer());
}
use of io.cdap.cdap.client.config.ClientConfig in project cdap by caskdata.
the class CLIConfig method checkConnection.
private void checkConnection(ClientConfig baseClientConfig, ConnectionConfig connectionInfo, AccessToken accessToken) throws IOException, UnauthenticatedException, UnauthorizedException {
ClientConfig clientConfig = new ClientConfig.Builder(baseClientConfig).setConnectionConfig(connectionInfo).setAccessToken(accessToken).build();
MetaClient metaClient = new MetaClient(clientConfig);
try {
metaClient.ping();
} catch (IOException e) {
throw new IOException("Check connection parameters and/or accesstoken", e);
}
}
Aggregations