forked from community/device-mgt-core
parent
cada581396
commit
bcb2c1ddb1
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.enforcement;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.ntask.core.Task;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DelegationTask implements Task {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DelegationTask.class);
|
||||
|
||||
@Override
|
||||
public void setProperties(Map<String, String> map) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
try {
|
||||
PolicyManager policyManager = new PolicyManagerImpl();
|
||||
List<DeviceType> deviceTypes = policyManager.applyChangesMadeToPolicies();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size());
|
||||
}
|
||||
if (!deviceTypes.isEmpty()) {
|
||||
DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance()
|
||||
.getDeviceManagementService();
|
||||
List<Device> devices = new ArrayList<>();
|
||||
for (DeviceType deviceType : deviceTypes) {
|
||||
try {
|
||||
devices.addAll(service.getAllDevices(deviceType.getName()));
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new PolicyManagementException("Error occurred while taking the devices", e);
|
||||
}
|
||||
}
|
||||
HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
|
||||
List<Device> toBeNotified = new ArrayList<>();
|
||||
|
||||
for (Device device : devices) {
|
||||
if (deviceIdPolicy.containsKey(device.getId())) {
|
||||
toBeNotified.add(device);
|
||||
}
|
||||
}
|
||||
if (!toBeNotified.isEmpty()) {
|
||||
PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified);
|
||||
enforcementDelegator.delegate();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PolicyManagementException e) {
|
||||
log.error("Error occurred while getting the policies applied to devices.", e);
|
||||
} catch (PolicyDelegationException e) {
|
||||
log.error("Error occurred while running the delegation task.", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<tasks-configuration xmlns:svns="http://org.wso2.securevault/configuration">
|
||||
|
||||
<!--
|
||||
The currently running server mode; possible values are:-
|
||||
STANDALONE, CLUSTERED, REMOTE, AUTO.
|
||||
In AUTO mode, the server startup checks whether clustering is enabled in the system,
|
||||
if so, CLUSTERED mode will be used, or else, the the server mode will be STANDALONE.
|
||||
-->
|
||||
<taskServerMode>AUTO</taskServerMode>
|
||||
|
||||
<!--
|
||||
To be used in CLUSTERED mode to notify how many servers are there in
|
||||
the task server cluster, the servers wait till this amount of servers
|
||||
are activated before the tasks are scheduled -->
|
||||
<taskServerCount>2</taskServerCount>
|
||||
|
||||
<!-- The default location resolver configuration -->
|
||||
<defaultLocationResolver>
|
||||
<locationResolverClass>org.wso2.carbon.ntask.core.impl.RoundRobinTaskLocationResolver</locationResolverClass>
|
||||
</defaultLocationResolver>
|
||||
|
||||
<!--
|
||||
if task-type-pattern matches and task-name-pattern matches, check existing addresses of address-pattern,
|
||||
and if addresses exist, select address in round-robin fashion, if not move onto next rule in sequence.
|
||||
<property name="rule-[order]">[task-type-pattern],[task-name-pattern],[address-pattern]</property>
|
||||
-->
|
||||
<!--defaultLocationResolver>
|
||||
<locationResolverClass>org.wso2.carbon.ntask.core.impl.RuleBasedLocationResolver</locationResolverClass>
|
||||
<properties>
|
||||
<property name="rule-1">HIVE_TASK,.*,192.168.2.*</property>
|
||||
<property name="rule-5">.*,.*,.*</property>
|
||||
</properties>
|
||||
</defaultLocationResolver-->
|
||||
|
||||
<!-- The address to which the remote task server should dispatch the trigger messages to,
|
||||
usually this would be an endpoint to a load balancer -->
|
||||
<taskClientDispatchAddress>https://localhost:9448</taskClientDispatchAddress>
|
||||
|
||||
<!-- The address of the remote task server -->
|
||||
<remoteServerAddress>https://localhost:9443</remoteServerAddress>
|
||||
|
||||
<!-- The username to authenticate to the remote task server -->
|
||||
<remoteServerUsername>admin</remoteServerUsername>
|
||||
|
||||
<!-- The password to authenticate to the remote task server -->
|
||||
<remoteServerPassword>admin</remoteServerPassword>
|
||||
|
||||
<!-- Below contain a sample to be used when using with secure vault -->
|
||||
<!--remoteServerPassword svns:secretAlias="remote.task.server.password"></remoteServerPassword-->
|
||||
|
||||
</tasks-configuration>
|
Loading…
Reference in new issue