@Override public void deleteDeployment(ContentReference reference) { localFileRepository.deleteDeployment(reference); } }
public File readRootFile(byte rootId, String filePath) throws RequestProcessingException { final HostFileRepository localFileRepository = domainController.getLocalFileRepository(); switch (rootId) { case DomainControllerProtocol.PARAM_ROOT_ID_FILE: { return localFileRepository.getFile(filePath); } case DomainControllerProtocol.PARAM_ROOT_ID_CONFIGURATION: { return localFileRepository.getConfigurationFile(filePath); } case DomainControllerProtocol.PARAM_ROOT_ID_DEPLOYMENT: { byte[] hash = HashUtil.hexStringToByteArray(filePath); return localFileRepository.getDeploymentRoot(hash); } default: { throw MESSAGES.invalidRootId(rootId); } } } };
/** * Synchronize the required files to a slave HC from the master DC if this is required. * @param fileRepository the HostFileRepository of the HC. * @param contentRepository the ContentRepository of the HC. * @param backup inidcates if this is a DC backup HC. * @param oldHash the hash of the deployment to be replaced. * @return true if the content should be pulled by the slave HC - false otherwise. */ public static byte[] synchronizeSlaveHostController(ModelNode operation, final PathAddress address, HostFileRepository fileRepository, ContentRepository contentRepository, boolean backup, byte[] oldHash) { ModelNode operationContentItem = operation.get(DeploymentAttributes.CONTENT_RESOURCE_ALL.getName()).get(0); byte[] newHash = operationContentItem.require(CONTENT_HASH.getName()).asBytes(); if (needRemoteContent(fileRepository, contentRepository, backup, oldHash)) { // backup DC needs to pull the content fileRepository.getDeploymentFiles(ModelContentReference.fromModelAddress(address, newHash)); } return newHash; }
@Override public File getFile(String relativePath, byte repoId, HostFileRepository localFileRepository) { return localFileRepository.getFile(relativePath); } });
@Override public File getDeploymentRoot(byte[] deploymentHash) { String hex = deploymentHash == null ? "" : HashUtil.bytesToHexString(deploymentHash); final File file = localFileRepository.getDeploymentRoot(deploymentHash); if(! file.exists()) { return getFile(hex, DomainControllerProtocol.PARAM_ROOT_ID_DEPLOYMENT); } return file; }
/** * Synchronize the required files to a slave HC from the master DC if this is required. * @param fileRepository the HostFileRepository of the HC. * @param contentRepository the ContentRepository of the HC. * @param backup inidcates if this is a DC backup HC. * @param oldHash the hash of the deployment to be replaced. * @return true if the content should be pulled by the slave HC - false otherwise. */ public static byte[] synchronizeSlaveHostController(ModelNode operation, final PathAddress address, HostFileRepository fileRepository, ContentRepository contentRepository, boolean backup, byte[] oldHash) { ModelNode operationContentItem = operation.get(DeploymentAttributes.CONTENT_RESOURCE_ALL.getName()).get(0); byte[] newHash = operationContentItem.require(CONTENT_HASH.getName()).asBytes(); if (needRemoteContent(fileRepository, contentRepository, backup, oldHash)) { // backup DC needs to pull the content fileRepository.getDeploymentFiles(ModelContentReference.fromModelAddress(address, newHash)); } return newHash; }
public File getFile(final String relativePath, final byte repoId, HostFileRepository localFileRepository) { if(connection.isConnected()) { try { return handler.executeRequest(new GetFileRequest(repoId, relativePath, localFileRepository), null).getResult().get(); } catch (Exception e) { throw HostControllerLogger.ROOT_LOGGER.failedToGetFileFromRemoteRepository(e); } } else { final File file = localFileRepository.getFile(relativePath); // using --cached-dc and the DC is unavailable, make sure the content exists locally. if (localHostInfo.isUsingCachedDc()) { if (! file.exists()) { throw HostControllerLogger.ROOT_LOGGER.failedToGetFileFromRemoteRepository(new RuntimeException("Content hash " + relativePath + " not found.")); } } return file; } } };
@Override public File getDeploymentRoot(ContentReference reference) { File file = localFileRepository.getDeploymentRoot(reference); if(! file.exists()) { return getFile(reference.getHexHash(), DomainControllerProtocol.PARAM_ROOT_ID_DEPLOYMENT); } return file; }
@Override public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) { if (resultAction == OperationContext.ResultAction.KEEP) { if (contentRepository != null) { //Master DC or backup if (oldHash != null && (newHash == null || !Arrays.equals(oldHash, newHash))) { // The old content is no longer used; clean from repos contentRepository.removeContent(ModelContentReference.fromModelAddress(address, oldHash)); } if (newHash != null) { contentRepository.addContentReference(ModelContentReference.fromModelAddress(address, newHash)); } } } else { if (fileRepository != null) { // backup DC needs to pull the content fileRepository.getDeploymentFiles(ModelContentReference.fromModelAddress(address, newHash)); } if (contentRepository != null) { if (newHash != null && (oldHash == null || !Arrays.equals(oldHash, newHash))) { // Due to rollback, the new content isn't used; clean from repos contentRepository.removeContent(ModelContentReference.fromModelAddress(address, newHash)); } } } } });
public File readRootFile(byte rootId, String filePath) throws RequestProcessingException { final HostFileRepository localFileRepository = domainController.getLocalFileRepository(); switch (rootId) { case DomainControllerProtocol.PARAM_ROOT_ID_FILE: { return localFileRepository.getFile(filePath); } case DomainControllerProtocol.PARAM_ROOT_ID_CONFIGURATION: { return localFileRepository.getConfigurationFile(filePath); } case DomainControllerProtocol.PARAM_ROOT_ID_DEPLOYMENT: { byte[] hash = HashUtil.hexStringToByteArray(filePath); return localFileRepository.getDeploymentRoot(new ContentReference(filePath, hash)); } default: { throw HostControllerLogger.ROOT_LOGGER.invalidRootId(rootId); } } } };
@Override public void deleteDeployment(ContentReference reference) { localFileRepository.deleteDeployment(reference); } }
public File getFile(final String relativePath, final byte repoId, HostFileRepository localFileRepository) { if(connection.isConnected()) { try { return handler.executeRequest(new GetFileRequest(repoId, relativePath, localFileRepository), null).getResult().get(); } catch (Exception e) { throw HostControllerLogger.ROOT_LOGGER.failedToGetFileFromRemoteRepository(e); } } else { final File file = localFileRepository.getFile(relativePath); // using --cached-dc and the DC is unavailable, make sure the content exists locally. if (localHostInfo.isUsingCachedDc()) { if (! file.exists()) { throw HostControllerLogger.ROOT_LOGGER.failedToGetFileFromRemoteRepository(new RuntimeException("Content hash " + relativePath + " not found.")); } } return file; } } };
@Override public File getDeploymentRoot(ContentReference reference) { File file = localFileRepository.getDeploymentRoot(reference); if(! file.exists()) { return getFile(reference.getHexHash(), DomainControllerProtocol.PARAM_ROOT_ID_DEPLOYMENT); } return file; }
@Override public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) { if (resultAction == OperationContext.ResultAction.KEEP) { if (contentRepository != null) { //Master DC or backup if (oldHash != null && (newHash == null || !Arrays.equals(oldHash, newHash))) { // The old content is no longer used; clean from repos contentRepository.removeContent(ModelContentReference.fromModelAddress(address, oldHash)); } if (newHash != null) { contentRepository.addContentReference(ModelContentReference.fromModelAddress(address, newHash)); } } } else { if (fileRepository != null) { // backup DC needs to pull the content fileRepository.getDeploymentFiles(ModelContentReference.fromModelAddress(address, newHash)); } if (contentRepository != null) { if (newHash != null && (oldHash == null || !Arrays.equals(oldHash, newHash))) { // Due to rollback, the new content isn't used; clean from repos contentRepository.removeContent(ModelContentReference.fromModelAddress(address, newHash)); } } } } });
public File readRootFile(byte rootId, String filePath) throws RequestProcessingException { final HostFileRepository localFileRepository = domainController.getLocalFileRepository(); switch (rootId) { case DomainControllerProtocol.PARAM_ROOT_ID_FILE: { return localFileRepository.getFile(filePath); } case DomainControllerProtocol.PARAM_ROOT_ID_CONFIGURATION: { return localFileRepository.getConfigurationFile(filePath); } case DomainControllerProtocol.PARAM_ROOT_ID_DEPLOYMENT: { byte[] hash = HashUtil.hexStringToByteArray(filePath); return localFileRepository.getDeploymentRoot(new ContentReference(filePath, hash)); } default: { throw HostControllerLogger.ROOT_LOGGER.invalidRootId(rootId); } } } };
@Override public void deleteDeployment(byte[] deploymentHash) { localFileRepository.deleteDeployment(deploymentHash); } }
public File getFile(final String relativePath, final byte repoId, HostFileRepository localFileRepository) { if(connection.isConnected()) { try { return handler.executeRequest(new GetFileRequest(repoId, relativePath, localFileRepository), null).getResult().get(); } catch (Exception e) { throw MESSAGES.failedToGetFileFromRemoteRepository(e); } } else { return localFileRepository.getFile(relativePath); } } };
if ((content.hasDefined(HASH))) { byte[] hash = content.require(HASH).asBytes(); File[] files = domainController.getLocalFileRepository().getDeploymentFiles(hash); if (files == null || files.length == 0) { remoteRepository.getDeploymentFiles(hash);
@Override public void handleRequest(DataInput input, ActiveOperation.ResultHandler<File> resultHandler, ManagementRequestContext<Void> context) throws IOException { final File localPath; switch (rootId) { case DomainControllerProtocol.PARAM_ROOT_ID_FILE: { localPath = localFileRepository.getFile(filePath); break; } case DomainControllerProtocol.PARAM_ROOT_ID_CONFIGURATION: { localPath = localFileRepository.getConfigurationFile(filePath); break; } case DomainControllerProtocol.PARAM_ROOT_ID_DEPLOYMENT: { byte[] hash = HashUtil.hexStringToByteArray(filePath); localPath = localFileRepository.getDeploymentRoot(hash); break; } default: { localPath = null; } } try { DomainRemoteFileRequestAndHandler.INSTANCE.handleResponse(input, localPath, ROOT_LOGGER, resultHandler, context); } catch (CannotCreateLocalDirectoryException e) { throw MESSAGES.cannotCreateLocalDirectory(e.getDir()); } catch (DidNotReadEntireFileException e) { throw MESSAGES.didNotReadEntireFile(e.getMissing()); } } }
@Override public void handleResult(ResultAction resultAction, OperationContext context, ModelNode operation) { if (resultAction == ResultAction.KEEP) { if (replacedHash != null && (newHash == null || !Arrays.equals(replacedHash, newHash))) { // The old content is no longer used; clean from repos ContentReference reference = ModelContentReference.fromModelAddress(address, replacedHash); if (contentRepository != null) { contentRepository.removeContent(reference); } else { fileRepository.deleteDeployment(reference); } } if (newHash != null && contentRepository != null) { contentRepository.addContentReference(ModelContentReference.fromModelAddress(address, newHash)); } } else if (newHash != null && (replacedHash == null || !Arrays.equals(replacedHash, newHash))) { // Due to rollback, the new content isn't used; clean from repos ContentReference reference = ModelContentReference.fromModelAddress(address, newHash); if (contentRepository != null) { contentRepository.removeContent(reference); } else { fileRepository.deleteDeployment(reference); } } } });