org.apache.axis2.deployment.repository.util.DeploymentFileData Java Examples

The following examples show how to use org.apache.axis2.deployment.repository.util.DeploymentFileData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBDeployer.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to handle security policies.
 *
 * @param file deployment data file.
 * @param axisService to be modified.
 * @return true if security is enabled, false otherwise.
 * @throws DataServiceFault
 */
private boolean handleSecurityProxy(DeploymentFileData file, AxisService axisService) throws DataServiceFault {
    try (FileInputStream fis = new FileInputStream(file.getFile().getAbsoluteFile())) {
        boolean secEnabled = false;
        StAXOMBuilder builder = new StAXOMBuilder(fis);
        OMElement documentElement =  builder.getDocumentElement();
        OMElement enableSecElement= documentElement.getFirstChildWithName(new QName(DBSFields.ENABLESEC));
        if (enableSecElement != null) {
            secEnabled = true;
        }
        OMElement policyElement= documentElement.getFirstChildWithName(new QName(DBSFields.POLICY));
        if (policyElement != null) {
            String policyKey = policyElement.getAttributeValue(new QName(DBSFields.POLICY_KEY));
            if (null == policyKey) {
                throw new DataServiceFault("Policy key element should contain a policy key in "
                        + file.getFile().getName());
            }
            Policy policy = PolicyEngine.getPolicy(DBUtils.getInputStreamFromPath(policyKey));
            axisService.getPolicySubject().attachPolicy(policy);
        }
        return secEnabled;
    }catch (Exception e) {
        throw new DataServiceFault(e, "Error in processing security policy");
    }
}
 
Example #2
Source File: DeviceTypePluginDeployer.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    try {
        DeviceTypeConfiguration deviceTypeConfiguration = getDeviceTypeConfiguration(
                deploymentFileData.getFile().getAbsoluteFile());
        String deviceType = deviceTypeConfiguration.getName();
        String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
        if (deviceType != null && !deviceType.isEmpty() && tenantDomain != null
                && !tenantDomain.isEmpty()) {
            DeviceTypeConfigIdentifier deviceTypeConfigIdentifier = new DeviceTypeConfigIdentifier(deviceType,
                                                                                                   tenantDomain);
            ServiceRegistration serviceRegistration = registerDeviceType(deviceTypeConfigIdentifier,
                                                                         deviceTypeConfiguration);
            this.deviceTypeServiceRegistrations.put(deploymentFileData.getAbsolutePath(), serviceRegistration);
            this.deviceTypeConfigurationDataMap.put(deploymentFileData.getAbsolutePath(),
                                                    deviceTypeConfigIdentifier);
        }
    } catch (Throwable e) {
        log.error("Cannot deploy deviceType : " + deploymentFileData.getName(), e);
        throw new DeploymentException("Device type file " + deploymentFileData.getName() + " is not deployed ", e);
    }

}
 
Example #3
Source File: DeviceTypePluginDeployerTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void init() throws NoSuchFieldException, IllegalAccessException, IOException, RegistryException {
    deviceTypePluginDeployer = Mockito.mock(DeviceTypePluginDeployer.class, Mockito.CALLS_REAL_METHODS);
    serviceRegistration = Mockito.mock(ServiceRegistration.class, Mockito.CALLS_REAL_METHODS);
    Mockito.doReturn(serviceRegistration).when(deviceTypePluginDeployer).registerDeviceType(Mockito.any(),
            Mockito.any());
    deviceTypeServiceRegistrations = DeviceTypePluginDeployer.class.getDeclaredField
            ("deviceTypeServiceRegistrations");
    deviceTypeServiceRegistrations.setAccessible(true);
    deviceTypeServiceRegistrations.set(deviceTypePluginDeployer, new ConcurrentHashMap());
    deviceTypeConfigurationDataMap = DeviceTypePluginDeployer.class.getDeclaredField
            ("deviceTypeConfigurationDataMap");
    deviceTypeConfigurationDataMap.setAccessible(true);
    deviceTypeConfigurationDataMap.set(deviceTypePluginDeployer, new ConcurrentHashMap());
    this.initializeCarbonContext();
    if (file.exists()) {
        deploymentFileData = new DeploymentFileData(file);
    }
    if (invalidFile.exists()) {
        invalidDeploymentFileData = new DeploymentFileData(invalidFile);
    }
}
 
Example #4
Source File: DBDeployer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a timer with a one minute delay, for re-deploying a data service.
 */
private void sheduleRedeploy(DeploymentFileData deploymentFileData, AxisService service) {
	Runnable faultyServiceRectifier = new FaultyServiceRectifier(service,
			deploymentFileData, configCtx);
	/* Retry in one minute */
	long retryIn = 1000 * 60;
	DBUtils.scheduleTask(faultyServiceRectifier, retryIn);
}
 
Example #5
Source File: DBDeployer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method checks if the given data service has a corresponding "services.xml" is available,
 * if so, the AxisService representing the data service is applied the instructions from its
 * "services.xml".
 */
private AxisService handleTransports(DeploymentFileData file, AxisService axisService) throws DataServiceFault {
	try (FileInputStream fis = new FileInputStream(file.getFile().getAbsoluteFile())) {
		StAXOMBuilder builder = new StAXOMBuilder(fis);
           OMElement documentElement =  builder.getDocumentElement();
           OMAttribute transports = documentElement.getAttribute(new QName(DBSFields.TRANSPORTS));
           if (transports != null) {
               String [] transportArr = transports.getAttributeValue().split(" ");
               axisService.setExposedTransports(Arrays.asList(transportArr));
           }
	} catch (Exception e) {
		throw new DataServiceFault(e, "Error in processing transports info");
	}
	return axisService;
}
 
Example #6
Source File: DBDeployer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Creates AxisService with the given deployment information.
 */
private AxisService processService(DeploymentFileData currentFile,
		AxisServiceGroup axisServiceGroup, ConfigurationContext configCtx)
		throws DataServiceFault {
	/*
		Security Comment
		CurrentFile contains the actual dbs data location in the server. there isn't any input from the user.
	 */
	AxisService axisService = createDBService(currentFile.getAbsolutePath(), configCtx.getAxisConfiguration());
	axisService.setParent(axisServiceGroup);
	axisService.setClassLoader(axisConfig.getServiceClassLoader());
       /* handle services.xml, if exists */
	this.handleTransports(currentFile, axisService);
	return axisService;
}
 
Example #7
Source File: DataServiceCappDeployer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Deploy data services.
 * adding the data service to the data services.
 * there can be multiple data sources as separate xml files.
 *
 * @param artifacts  list of artifacts to be deployed.
 * @param axisConfig axis configuration.
 */
private void deployDataSources(List<Artifact> artifacts, AxisConfiguration axisConfig)
        throws DeploymentException {
    for (Artifact artifact : artifacts) {
        if (DS_TYPE.equals(artifact.getType())) {
            List<CappFile> files = artifact.getFiles();
            if (files == null || files.isEmpty()) {
                throw new DeploymentException("DataServiceCappDeployer::deployDataServices --> "
                                                      + "Error No data services found in the artifact to deploy");
            }
            for (CappFile cappFile : files) {
                String fileName = cappFile.getName();
                String dataServiceConfigPath = artifact.getExtractedPath() + File.separator + fileName;

                File file = new File(dataServiceConfigPath);
                if (!file.exists()) {
                    throw new DeploymentException("DataServiceCappDeployer::deployDataServices --> "
                                                          + "Error Data service file cannot be found in artifact, "
                                                          + "file name - " + fileName);
                }
                // access the deployment engine through axis config
                DeploymentEngine deploymentEngine = (DeploymentEngine) axisConfig.getConfigurator();
                Deployer deployer = deploymentEngine.getDeployer(DS_DIR, "dbs");

                try {
                    // Call the deploy method of the deployer
                    deployer.deploy(new DeploymentFileData(new File(dataServiceConfigPath), deployer));
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                } catch (DeploymentException e) {
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                    throw new DeploymentException(
                            "DataServiceCappDeployer::deployDataServices --> "
                                    + "Error in deploying data service: " + e.getMessage(), e);
                }
            }
        }
    }
}
 
Example #8
Source File: CappDeployer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Axis2 deployment engine will call this method when a .car archive is deployed. So we only have to call the
 * cAppDeploymentManager to deploy it using the absolute path of the deployed .car file.
 *
 * @param deploymentFileData - info about the deployed file
 * @throws DeploymentException - error while deploying cApp
 */
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    String artifactPath = deploymentFileData.getAbsolutePath();
    try {
        deployCarbonApps(artifactPath);
    } catch (Exception e) {
        log.error("Error while deploying carbon application " + artifactPath, e);
    }

    super.deploy(deploymentFileData);
}
 
Example #9
Source File: SynapseAppDeployer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Deploy class mediators contains in the CApp
 *
 * @param artifacts List of Artifacts contains in the capp
 * @param axisConfig AxisConfiguration of the current tenant
 * @throws DeploymentException if something goes wrong while deployment
 */
private void deployClassMediators(List<Artifact.Dependency> artifacts,
                                 AxisConfiguration axisConfig) throws DeploymentException {
    for (Artifact.Dependency dependency : artifacts) {

        Artifact artifact = dependency.getArtifact();
        if (!validateArtifact(artifact)) {
            continue;
        }

        if (SynapseAppDeployerConstants.MEDIATOR_TYPE.endsWith(artifact.getType())) {

            Deployer deployer = getClassMediatorDeployer(axisConfig);

            if (deployer != null) {
                artifact.setRuntimeObjectName(artifact.getName());
                String fileName = artifact.getFiles().get(0).getName();
                String artifactPath = artifact.getExtractedPath() + File.separator + fileName;

                try {
                    deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                } catch (DeploymentException e) {
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                    throw e;
                }
            }
        }
    }
}
 
Example #10
Source File: FaultyServiceRectifier.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public FaultyServiceRectifier(AxisService service,
		DeploymentFileData deploymentData, ConfigurationContext configCtx) {
	this.deploymentFileData = deploymentData;
	this.configurationCtx = configCtx;
	try {
	    this.tenantId = Constants.SUPER_TENANT_ID; // PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
	} catch (Throwable e) {
		/* this is done in the case of running unit tests, the above code fails */
		this.tenantId = -1;
	}
}
 
Example #11
Source File: ArtifactDeploymentManager.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Function to execute artifact deployment
 */
public void deploy() {

    Set<Map.Entry<String, Deployer>> deploymentEntries = dirToDeployerMap.entrySet();
    for (Map.Entry<String, Deployer> deployerEntry : deploymentEntries) {
        if (log.isDebugEnabled()) {
            log.debug("Deploying artifacts from: " + deployerEntry.getKey());
        }

        File confDirFile = new File(deployerEntry.getKey());
        if (confDirFile.isDirectory() && confDirFile.exists()) {
            File[] configFiles = confDirFile.listFiles();
            if (configFiles == null) {
                if (log.isDebugEnabled()) {
                    log.debug("No configurations found to deploy in: " + deployerEntry.getKey());
                }
                continue;
            }

            // Deploy each config file
            for (File configFile : configFiles) {
                if (configFile.isFile()) {
                    try {
                        deployerEntry.getValue().deploy(new DeploymentFileData(configFile, deployerEntry.getValue()));
                    } catch (DeploymentException e) {
                        log.error("Error occurred while deploying : " + configFile.getName(), e);
                    }
                }
            }
        }
    }
}
 
Example #12
Source File: DeviceTypeCAppDeployer.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
void deploy(Deployer deployer, Artifact artifact) throws DeploymentException {
    String fileName = artifact.getFiles().get(0).getName();
    String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
    try {
        deployer.deploy(new DeploymentFileData(new File(artifactPath)));
        artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
    } catch (Exception e) {
        artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
        log.error("Deployment is failed due to " + e.getMessage(), e);
        throw new DeploymentException(e.getMessage(), e);
    }
}
 
Example #13
Source File: DeviceTypeCAppDeployer.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
private void undeploy(Deployer deployer, Artifact artifact) throws DeploymentException {
    String fileName = artifact.getFiles().get(0).getName();
    String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
    try {
        deployer.undeploy(new DeploymentFileData(new File(artifactPath), deployer).getAbsolutePath());
        artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_PENDING);
    } catch (Exception e) {
        artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
        log.error("Undeployment is failed due to " + e.getMessage(), e);
        throw new DeploymentException(e.getMessage(), e);
    }
}
 
Example #14
Source File: SynapseAppDeployer.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Deploy synapse libraries contains in the CApp
 *
 * @param artifacts  List of Artifacts contains in the capp
 * @param axisConfig AxisConfiguration of the current tenant
 * @throws DeploymentException if something goes wrong while deployment
 */
private void deploySynapseLibrary(List<Artifact.Dependency> artifacts,
                                  AxisConfiguration axisConfig) throws DeploymentException {
    for (Artifact.Dependency dependency : artifacts) {

        Artifact artifact = dependency.getArtifact();
        if (!validateArtifact(artifact)) {
            continue;
        }

        if (SynapseAppDeployerConstants.SYNAPSE_LIBRARY_TYPE.equals(artifact.getType())) {

            Deployer deployer = getSynapseLibraryDeployer(axisConfig);

            if (deployer != null) {
                artifact.setRuntimeObjectName(artifact.getName());
                String fileName = artifact.getFiles().get(0).getName();
                String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
                String artifactDir = getArtifactDirPath(axisConfig, SynapseAppDeployerConstants.SYNAPSE_LIBS);
                File artifactInRepo = new File(artifactDir + File.separator + fileName);
                if (artifactInRepo.exists()) {
                    log.warn("Synapse Library " + fileName + " already found in " + artifactInRepo.getAbsolutePath() +
                            ". Ignoring CAPP's artifact");
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                } else {
                    try {
                        deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
                        artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                        try {
                            String artifactName = getArtifactName(artifactPath, axisConfig);
                            SynapseConfiguration configuration = getSynapseConfiguration(axisConfig);
                            if (artifactName != null) {
                                if (configuration.getSynapseImports().get(artifactName) == null) {
                                    String libName = artifactName.substring(artifactName.lastIndexOf("}") + 1);
                                    String libraryPackage = artifactName.substring(1, artifactName.lastIndexOf("}"));
                                    updateStatus(artifactName, libName, libraryPackage, ServiceBusConstants.ENABLED, axisConfig);
                                }
                            }
                        } catch (AxisFault axisFault) {
                            log.error("Unable to update status for the synapse library : " + axisFault.getMessage());
                        } catch (NullPointerException nullException) {
                            log.error("Error while getting qualified name of the synapse library : " + nullException.getMessage());
                        }
                    } catch (DeploymentException e) {
                        artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                        log.error("Error while deploying the synapse library : " + e.getMessage());
                        throw e;
                    }
                }
            }
        }
    }
}
 
Example #15
Source File: CloudControllerDeployer.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {

        log.debug("Started to deploy the deployment artifact: " + deploymentFileData.getFile());

        // since cloud-controller.xml resides in repository/conf
        if (deploymentFileData.getName().contains(FILE_NAME)) {

            OMElement docElt = AxiomXpathParserUtil.parse(deploymentFileData.getFile());

            CloudControllerConfigParser.parse(docElt);

            // update map
            fileToIaasProviderListMap.put(deploymentFileData.getAbsolutePath(),
                    new ArrayList<IaasProvider>(
                            CloudControllerConfig.getInstance()
                                    .getIaasProviders()));

            log.info("Successfully deployed the cloud-controller XML file located at " +
                    deploymentFileData.getAbsolutePath());
        }

    }
 
Example #16
Source File: DeviceTypePluginDeployerTest.java    From carbon-device-mgt with Apache License 2.0 4 votes vote down vote up
@Test(description = "Testing exception for non existing xml file", expectedExceptions = {org.apache.axis2.deployment
        .DeploymentException.class})
public void unDeployInvalidXml() throws DeploymentException, IllegalAccessException {
    deviceTypePluginDeployer.deploy(new DeploymentFileData(new File("src/test/resources/notExist.xml")));
}
 
Example #17
Source File: SynapseAppDeployer.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * This deploys artifacts when a list of artifacts is provided
 *
 * @param artifacts - List of artifacts which should be deployed
 * @param carbonApp  - CarbonApplication instance to check for artifacts
 * @param axisConfig - AxisConfiguration of the current tenant
 * @throws DeploymentException if some error occurs while deployment
 */
public void deployArtifactType(List<Artifact.Dependency> artifacts, CarbonApplication carbonApp,
                            AxisConfiguration axisConfig) throws DeploymentException {
    for (Artifact.Dependency dep : artifacts) {
        Artifact artifact = dep.getArtifact();
        String artifactType = artifact.getType();
        String artifactDirName = getArtifactDirName(artifactType);

        if (!validateArtifact(artifact) || artifactDirName == null) {
            continue;
        }

        Deployer deployer = getDeployer(artifact.getType());
        String artifactDir = getArtifactDirPath(axisConfig, artifactDirName);

        artifact.setRuntimeObjectName(artifact.getName());

        if (deployer != null) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            File artifactInRepo = new File(artifactDir + File.separator + fileName);

            if (SynapseAppDeployerConstants.SEQUENCE_TYPE.equals(artifact.getType()) &&
                    handleMainFaultSeqDeployment(artifact, axisConfig, deployer)) {
                log.debug("Handling main and fault sequence deployment");
            } else if (artifactInRepo.exists()) {
                log.warn("Artifact " + fileName + " already found in " + artifactInRepo.getAbsolutePath() +
                        ". Ignoring CAPP's artifact");
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
            } else {
                try {
                    setCustomLogContent(deployer, carbonApp);
                    deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                } catch (DeploymentException e) {
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                    throw e;
                } catch (Throwable throwable) {
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                    // Since there can be different deployers, they can throw any error.
                    // So need to handle unhandled exception has occurred during deployement. Hence catch all and
                    // wrap it with DeployementException and throw it
                    throw new DeploymentException(throwable);
                } finally {
                    //clear the log appender once deployment is finished to avoid appending the
                    //same log to other classes.
                    setCustomLogContent(deployer, null);
                    CustomLogSetter.getInstance().clearThreadLocalContent();
                }
            }
        }
    }
}
 
Example #18
Source File: DBDeployer.java    From micro-integrator with Apache License 2.0 2 votes vote down vote up
/**
 * Checks whether the service that is being deployed is already marked as a faulty service
 *
 * @param deploymentFileData    DeploymentFileData instance corresponding to the service being
 *                              deployed.
 * @return                      Boolean representing the existence of the service as a faulty
 *                              service
 */
private boolean isFaultyService(DeploymentFileData deploymentFileData) {
    String faultyServiceFilePath = deploymentFileData.getFile().getAbsolutePath();
    AxisService faultyService = CarbonUtils.getFaultyService(faultyServiceFilePath, this.configCtx);
    return faultyService != null;
}