private void setPermissionsToOwner(File f) { boolean b = true; try { b = f.setReadable(false, false); b &= f.setWritable(false, false); } finally { b &= f.setReadable(true, true); b &= f.setWritable(true, true); } if (b) { this.log(Level.FINE, "Permissions set to file %s", f.getAbsolutePath()); } }
public static void main(String[] args) throws Throwable { Utils.setTimeDriftThreshold(TIME_DRIFT_THRESHOLD_MICROS); ManagementHost h = new ManagementHost(); h.initializeHostAndServices(args); Runtime.getRuntime().addShutdownHook(new Thread(() -> { h.log(Level.WARNING, "Host stopping ..."); h.stop(); h.log(Level.WARNING, "Host is stopped"); })); }
/** * Sets read/write permissions only to the owner of the encryption file. */ private void setEncryptionFilePermissions() throws Throwable { String encFileParam = System.getProperty(EncryptionUtils.ENCRYPTION_KEY); if (encFileParam == null) { return; } File f = new File(encFileParam); File parent = f.getParentFile(); // create parent folder if it does not exist if (!parent.exists() && !parent.mkdirs()) { log(Level.SEVERE, "Cannot create folders %s for encryption file.", parent.getAbsolutePath()); throw new IOException("Cannot create " + parent.getAbsolutePath()); } // dummy call to initialize the EncryptionUtils and create the encryption file EncryptionUtils.encrypt(null); try { // set file permissions setPermissionsToOwner(f); } catch (Throwable e) { log(Level.SEVERE, "Cannot change permissions of file %s. Error: %s", encFileParam, e.getMessage()); throw e; } }
protected ManagementHost initializeHostAndServices(String[] args) throws Throwable { log(Level.INFO, "Initializing ..."); initialize(args); log(Level.INFO, "Registering service interceptors ..."); registerOperationInterceptors(); log(Level.INFO, "Starting ..."); start(); log(Level.INFO, "Setting authorization context ..."); // Set system user's authorization context to allow the services start privileged access. setAuthorizationContext(getSystemAuthorizationContext()); log(Level.INFO, "**** Management host starting ... ****"); startFabricServices(); startManagementServices(); startClosureServices(this, startMockHostAdapterInstance); startSwaggerService(); startCustomSwaggerService(); log(Level.INFO, "**** Management host started. ****"); log(Level.INFO, "**** Migration service starting... ****"); super.startFactory(new LegacyMigrationTaskService()); super.startFactory(new MigrationTaskService()); // Clean up authorization context to avoid privileged access. setAuthorizationContext(null); return this; }
log(Level.SEVERE, "Cannot register service factory for %s: %s", serviceMetadata.serviceClass.getCanonicalName(), Utils.toString(e));
private static void waitForDefaultRegistryCreated(ManagementHost host) { TestContext ctx = new TestContext(1, Duration.ofSeconds(120)); host.log(Level.INFO, "Waiting for default registry to start."); host.registerForServiceAvailability(ctx.getCompletion(), RegistryService.DEFAULT_INSTANCE_LINK); ctx.await(); host.log(Level.INFO, "Default registry started."); }
/** * Start all services required to support management of infrastructure and applications. */ protected void startCommonServices() throws Throwable { this.log(Level.INFO, "Common service starting ..."); HostInitCommonServiceConfig.startServices(this); HostInitAuthServiceConfig.startServices(this); HostInitUpgradeServiceConfig.startServices(this); registerForServiceAvailability(AuthBootstrapService.startTask(this), true, AuthBootstrapService.FACTORY_LINK); if (!ConfigurationUtil.isVca()) { registerForServiceAvailability(ProjectsTransformationBootstrapService.startTask(this), true, ProjectsTransformationBootstrapService.FACTORY_LINK, ProjectFactoryService.SELF_LINK); } this.log(Level.INFO, "Common services started."); }
/** * Start all services required to support management of infrastructure and applications. */ protected void startManagementServices() throws Throwable { this.log(Level.INFO, "Management service starting ..."); registerForServiceAvailability(CaSigningCertService.startTask(this), true, CaSigningCertService.FACTORY_LINK); HostInitComputeServicesConfig.startServices(this, false); HostInitComputeBackgroundServicesConfig.startServices(this); HostInitRequestServicesConfig.startServices(this); HostInitImageServicesConfig.startServices(this); HostInitUiServicesConfig.startServices(this); HostInitHarborServices.startServices(this, startMockHostAdapterInstance); HostInitDockerAdapterServiceConfig.startServices(this, startMockHostAdapterInstance); HostInitKubernetesAdapterServiceConfig.startServices(this, startMockHostAdapterInstance); HostInitRegistryAdapterServiceConfig.startServices(this); this.log(Level.INFO, "Management services started."); }
static ManagementHost createManagementHost(String[] args) throws Throwable { ManagementHost h = new ManagementHost(); h.initialize(args); h.registerOperationInterceptors(); h.start(); h.setAuthorizationContext(h.getSystemAuthorizationContext()); h.log(Level.INFO, "**** Management host starting ... ****"); h.startFabricServices(); h.startManagementServices(); waitForDefaultRegistryCreated(h); h.log(Level.INFO, "**** Management host started. ****"); h.setAuthorizationContext(null); Runtime.getRuntime().addShutdownHook(new Thread(() -> { h.log(Level.WARNING, "Host stopping ..."); h.stop(); h.log(Level.WARNING, "Host is stopped"); })); return h; }
private void verifyDummyStateServiceCompletes(String dummyTaskSelfLink) throws InterruptedException { TestContext context = new TestContext(1, Duration.ofSeconds(320)); // Get container and verify that its name has been updated by subscriber. DummyServiceTaskState dummyState = sendOperation(host, UriUtils.buildUri(host, dummyTaskSelfLink), null, DummyServiceTaskState.class, Action.GET); while (dummyState.taskInfo.stage != TaskState.TaskStage.FINISHED && dummyState.taskSubStage != SubStage.COMPLETED) { host.log(Level.WARNING, "Not ready yet!"); Thread.sleep(3000L); dummyState = sendOperation(host, UriUtils.buildUri(host, dummyTaskSelfLink), null, DummyServiceTaskState.class, Action.GET); } context.completeIteration(); }
@Override public boolean isReady() { try { SimpleEntry<Integer, String> response = doGet(uri, headers); assertEquals(HttpURLConnection.HTTP_OK, (int) response.getKey()); String body = switchToUnixLineEnds(response.getValue()); for (ManagementHost host2 : hosts) { assertTrue("Host " + host2.getUri() + " should be present!", body.contains("\"groupReference\": \"" + host2.getUri() + "/core/node-groups/default\",\n \"status\": \"AVAILABLE\"")); } } catch (Throwable e) { host.log(Level.WARNING, "Request to [%s] failed with: [%s].", NODE_GROUPS, e.getMessage()); return false; } return true; }
log(Level.INFO, "Setting authorization context ...");