initial public commit

This commit is contained in:
2021-09-06 17:46:59 +03:00
commit b744b08829
824 changed files with 91593 additions and 0 deletions

View File

@ -0,0 +1,46 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-manager
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.system.management.profile.manager;
import ru.entaxy.esb.system.management.bundle.jpa.dto.BundleDto;
import ru.entaxy.esb.system.management.profile.manager.dto.ProfileDto;
import java.util.List;
public interface ProfileManager {
BundleDto installProfile(ProfileDto profileDto) throws Exception;
BundleDto startProfile(ProfileDto profileDto) throws Exception;
BundleDto stopProfile(ProfileDto profileDto) throws Exception;
ProfileDto getProfile(ProfileDto profileDto) throws Exception;
List<ProfileDto> getProfiles() throws Exception;
List<ProfileDto> getPermissionsBySubject(String uuid) throws Exception;
List<ProfileDto> getPermissionsByObject(String uuid) throws Exception;
void uninstallProfile(ProfileDto profileDto) throws Exception;
void restore() throws Exception;
}

View File

@ -0,0 +1,214 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-manager
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.system.management.profile.manager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ru.entaxy.esb.system.connector.entity.Connector;
import ru.entaxy.esb.system.jpa.SystemService;
import ru.entaxy.esb.system.jpa.entity.ExportAllowed;
import ru.entaxy.esb.system.jpa.entity.System;
import ru.entaxy.esb.system.management.bridge.profile.manager.BridgeProfileManager;
import ru.entaxy.esb.system.management.bridge.profile.manager.dto.BridgeProfileDto;
import ru.entaxy.esb.system.management.bundle.jpa.dto.BundleDto;
import ru.entaxy.esb.system.management.bundle.manager.BundleManager;
import ru.entaxy.esb.system.management.connector.manager.ConnectorManager;
import ru.entaxy.esb.system.management.permission.manager.PermissionManager;
import ru.entaxy.esb.system.management.profile.manager.dto.ProfileDto;
import ru.entaxy.esb.system.management.profile.manager.mapper.ProfileMapper;
import ru.entaxy.esb.system.management.route.manager.RouteManager;
import java.io.IOException;
import java.util.List;
public class ProfileManagerImpl implements ProfileManager {
private static final Log LOG = LogFactory.getLog(ProfileManagerImpl.class);
private static final String PROFILE = "profile";
private boolean isRestoreFromDB;
private BundleManager bundleManager;
private SystemService systemService;
private ProfileMapper profileMapper;
private BridgeProfileManager bridgeProfileManager;
private ConnectorManager connectorManager;
private PermissionManager permissionManager;
private RouteManager routeManager;
@Override
public BundleDto installProfile(ProfileDto profileDto) throws Exception {
BundleDto bundle;
System system = null;
try {
system = systemService.create(profileMapper.toSystemEntity(profileDto));
bundle = bundleManager.installAndStartBundle(system.getName(), PROFILE,
String.valueOf(system.getVersion()));
systemService.setBundleEntity(system, profileMapper.toBundleEntity(bundle));
routeManager.createDefaultRoute(profileDto.getName());
} catch (Exception ex) {
systemService.remove(system);
throw ex;
}
return bundle;
}
@Override
public BundleDto startProfile(ProfileDto profileDto) throws Exception {
System system = systemService.getByUuid(profileDto.getUuid());
BundleDto bundle = bundleManager.startBundle(profileMapper.toBundleDto(system.getBundleEntity()));
systemService.setBundleEntity(system, profileMapper.toBundleEntity(bundle));
return bundle;
}
@Override
public BundleDto stopProfile(ProfileDto profileDto) throws Exception {
System system = systemService.getByUuid(profileDto.getUuid());
stopProfileDependency(system);
BundleDto bundle = bundleManager.stopBundle(profileMapper.toBundleDto(system.getBundleEntity()));
systemService.setBundleEntity(system, profileMapper.toBundleEntity(bundle));
return bundle;
}
@Override
public void uninstallProfile(ProfileDto profileDto) throws Exception {
System system = systemService.getByUuid(profileDto.getUuid());
uninstallProfileDependency(system);
bundleManager.uninstallBundle(system.getName(), PROFILE, String.valueOf(system.getVersion()));
systemService.remove(system.getId());
}
@Override
public ProfileDto getProfile(ProfileDto profileDto) throws Exception {
return profileMapper.toProfileDto(systemService.getByUuid(profileDto.getUuid()));
}
@Override
public List<ProfileDto> getProfiles() throws Exception {
return profileMapper.toListProfiles(systemService.getFullSystemListByOriginIsEmpty());
}
@Override
public List<ProfileDto> getPermissionsBySubject(String uuid) throws Exception {
return profileMapper.toListProfiles(systemService.getFullSystemListByPermissionBySubject(uuid));
}
@Override
public List<ProfileDto> getPermissionsByObject(String uuid) throws Exception {
return profileMapper.toListProfiles(systemService.getFullSystemListByPermissionByObject(uuid));
}
@Override
public void restore() throws Exception {
if (!isRestoreFromDB)
return;
for (System system : systemService.getSystemList()) {
if (system.getOrigin() == null || system.getOrigin().isEmpty()) {
try {
LOG.info("Restore profile of system " + system.getName());
bundleManager.restore(profileMapper.toBundleDto(system.getBundleEntity()));
} catch (IOException e) {
LOG.warn("Recreate profile of system " + system.getName());
restoreProfile(system);
}
try {
if(system.getDefaultRoute())
routeManager.createDefaultRoute(system.getName());
} catch (Exception e) {
LOG.warn("Error from create default route " + system.getName());
throw e;
}
}
}
}
private void restoreProfile(System system) throws Exception {
BundleDto bundle = bundleManager.installBundle(system.getName(), PROFILE,
String.valueOf(system.getVersion()));
bundle.setStatus(profileMapper.toBundleDto(system.getBundleEntity()).getStatus());
bundleManager.checkCurrentBundleStatus(bundle);
systemService.setBundleEntity(system, profileMapper.toBundleEntity(bundle));
}
private void stopProfileDependency(System system) throws Exception {
if (system.getConnectors() != null) {
for (Connector connector : system.getConnectors()) {
connectorManager.stopConnector(connector);
}
}
BridgeProfileDto bridgeProfileDto = profileMapper.toBridgeProfileDto(system);
for (ExportAllowed exportAllowed : system.getExportAlloweds()) {
bridgeProfileDto.setEsbName(exportAllowed.getName());
bridgeProfileManager.stopBridgeProfile(bridgeProfileDto);
}
}
private void uninstallProfileDependency(System system) throws Exception {
if (system.getConnectors() != null) {
for (Connector connector : system.getConnectors()) {
connectorManager.uninstallConnector(connector);
}
}
BridgeProfileDto bridgeProfileDto = profileMapper.toBridgeProfileDto(system);
for (ExportAllowed exportAllowed : system.getExportAlloweds()) {
bridgeProfileDto.setEsbName(exportAllowed.getName());
bridgeProfileManager.uninstallBridgeProfile(bridgeProfileDto);
}
permissionManager.removeAllPermission(system.getId());
routeManager.uninstallDefaultRoute(system.getName());
}
public void setProfileMapper(ProfileMapper profileMapper) {
this.profileMapper = profileMapper;
}
public void setBundleManager(BundleManager bundleManager) {
this.bundleManager = bundleManager;
}
public void setSystemService(SystemService systemService) {
this.systemService = systemService;
}
public void setBridgeProfileManager(BridgeProfileManager bridgeProfileManager) {
this.bridgeProfileManager = bridgeProfileManager;
}
public void setRouteManager(RouteManager routeManager) {
this.routeManager = routeManager;
}
public void setConnectorManager(ConnectorManager connectorManager) {
this.connectorManager = connectorManager;
}
public void setPermissionManager(PermissionManager permissionManager) {
this.permissionManager = permissionManager;
}
public void setIsRestoreFromDB(String isRestoreFromDB) {
this.isRestoreFromDB = Boolean.parseBoolean(isRestoreFromDB);
}
}

View File

@ -0,0 +1,137 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-manager
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.system.management.profile.manager.dto;
import ru.entaxy.esb.system.management.connector.manager.dto.ConnectorDto;
import java.util.Date;
import java.util.Set;
public class ProfileDto {
private String uuid;
private String name;
private String description;
private Date editDate;
private String editedBy;
private Date createDate;
private String createdBy;
private String version;
private String type;
private String status;
private Set<ConnectorDto> connectors;
private Set<String> exportAlloweds;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getEditDate() {
return editDate;
}
public void setEditDate(Date editDate) {
this.editDate = editDate;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getEditedBy() {
return editedBy;
}
public void setEditedBy(String editedBy) {
this.editedBy = editedBy;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Set<ConnectorDto> getConnectors() {
return connectors;
}
public void setConnectors(Set<ConnectorDto> connectors) {
this.connectors = connectors;
}
public Set<String> getExportAlloweds() {
return exportAlloweds;
}
public void setExportAlloweds(Set<String> exportAlloweds) {
this.exportAlloweds = exportAlloweds;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

View File

@ -0,0 +1,84 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-manager
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.system.management.profile.manager.mapper;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import ru.entaxy.esb.system.jpa.entity.ExportAllowed;
import ru.entaxy.esb.system.jpa.entity.System;
import ru.entaxy.esb.system.management.bridge.profile.manager.dto.BridgeProfileDto;
import ru.entaxy.esb.system.management.bundle.jpa.dto.BundleDto;
import ru.entaxy.esb.system.management.bundle.jpa.entity.BundleEntity;
import ru.entaxy.esb.system.management.connector.manager.mapper.ConnectorMapper;
import ru.entaxy.esb.system.management.profile.manager.dto.ProfileDto;
import java.util.List;
import java.util.Set;
@Mapper(componentModel = "spring", uses = {ConnectorMapper.class},
injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface ProfileMapper {
@Mappings({
@Mapping(target = "version", source = "version", qualifiedByName = "generateVersion"),
@Mapping(target = "createDate", expression = "java(new java.util.Date())"),
})
System toSystemEntity(ProfileDto profileDto);
@Mappings({
@Mapping(target = "status", source = "bundleEntity.status"),
})
ProfileDto toProfileDto(System system);
@Mappings({
@Mapping(target = "name", source = "bundleName"),
@Mapping(target = "url", source = "bundleUrl"),
})
BundleEntity toBundleEntity(BundleDto bundle);
@Mappings({
@Mapping(target = "bundleName", source = "name"),
@Mapping(target = "bundleUrl", source = "url"),
})
BundleDto toBundleDto(BundleEntity bundle);
Set<ExportAllowed> toExportAllowedEntities(Set<String> exportAlloweds);
Set<String> toExportAlloweds(Set<ExportAllowed> exportAlloweds);
default ExportAllowed map(String exportAllowed) {
ExportAllowed exportAllowedEntity = new ExportAllowed();
exportAllowedEntity.setName(exportAllowed);
return exportAllowedEntity;
}
default String map(ExportAllowed exportAllowed) {
return exportAllowed != null ? exportAllowed.getName() : null;
}
List<ProfileDto> toListProfiles(List<System> systemList);
@Mappings({
@Mapping(target = "profileUuid", source = "uuid")
})
BridgeProfileDto toBridgeProfileDto(System system);
}

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~~~~~~licensing~~~~~~
profile-manager
==========
Copyright (C) 2020 - 2021 EmDev LLC
==========
Licensed 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.
~~~~~~/licensing~~~~~~
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<cm:property-placeholder persistent-id="ru.entaxy.esb" update-strategy="reload">
<cm:default-properties>
<cm:property name="is.restore.from.db" value="true"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="profileManager" class="ru.entaxy.esb.system.management.profile.manager.ProfileManagerImpl"
init-method="restore">
<property name="isRestoreFromDB" value="${is.restore.from.db}"/>
<property name="systemService" ref="systemService"/>
<property name="profileMapper" ref="profileMapper"/>
<property name="bundleManager" ref="bundleManager"/>
<property name="connectorManager" ref="connectorManager"/>
<property name="bridgeProfileManager" ref="bridgeProfileManager"/>
<property name="permissionManager" ref="permissionManager"/>
<property name="routeManager" ref="routeManager"/>
</bean>
<service ref="profileManager" interface="ru.entaxy.esb.system.management.profile.manager.ProfileManager"/>
<bean id="profileMapper" class="ru.entaxy.esb.system.management.profile.manager.mapper.ProfileMapperImpl">
<argument ref="connectorMapper"/>
</bean>
<bean id="connectorMapper" class="ru.entaxy.esb.system.management.connector.manager.mapper.ConnectorMapperImpl"/>
<bean id="bridgeProfileMapper"
class="ru.entaxy.esb.system.management.bridge.profile.manager.mapper.BridgeProfileMapperImpl"/>
<reference id="systemService"
interface="ru.entaxy.esb.system.jpa.SystemService"
timeout="30000"
availability="mandatory"/>
<reference id="bundleManager"
interface="ru.entaxy.esb.system.management.bundle.manager.BundleManager"
timeout="30000"
availability="mandatory"/>
<reference id="connectorManager"
interface="ru.entaxy.esb.system.management.connector.manager.ConnectorManager"
timeout="30000"
availability="mandatory"/>
<reference id="bridgeProfileManager"
interface="ru.entaxy.esb.system.management.bridge.profile.manager.BridgeProfileManager"
timeout="30000"
availability="mandatory"/>
<reference id="permissionManager"
interface="ru.entaxy.esb.system.management.permission.manager.PermissionManager"
timeout="30000"
availability="mandatory"/>
<reference id="routeManager"
interface="ru.entaxy.esb.system.management.route.manager.RouteManager"
timeout="30000"
availability="mandatory"/>
</blueprint>